I have a ScatterViewItem which contains a Canvas
<Ellipse x:Name="Outer_Ellipse" Fill="White" Width="200" Height="200"></Ellipse>
<Ellipse Fill="Red" Canvas.Top ="15" Canvas.Left="15" Canvas.Right="15" Canvas.Bottom="15" Width="170" Height="170" ></Ellipse>
</Canvas>
</s:ScatterViewItem>
Id like to provide a Custom Shape so that the default rectangle shape is not show (here is a picture of my current implementation .
I followed this example here link text and have consulted the Puzzle that comes with the SDK but I am unable to get it working, my ScatterViewItem is blank.
I defined a path in the SurfaceWindow.Resources
<Path x:Key="ScatterShape" Fill="Blue">
<Path.Data>
<EllipseGeometry
RadiusX="200"
RadiusY="200">
</EllipseGeometry>
</Path.Data>
</Path>
And copied the style attributes from the link above. I created my CustomShape.cs as instructed and then created the ScatterViewItem.
System.Windows.Shapes.Path path;
path = (System.Windows.Shapes.Path)Resources["ScatterShape"];
CustomShape poly = new CustomShape(path.Data);
ScatterViewItem item = new ScatterViewItem();
item.Content = poly;
item.CanScale = false;
Binding binding = new Binding();
binding.Source = poly;
item.SetBinding(ScatterViewItem.DataContextProperty, binding);
scatter.Items.Add(item)
Im slightly confused with the above code since my understanding with the line
item.Content = poly
would overwrite the content of the ScatterViewItem (i.e in my case the Canvas or in another case say an Image). For the time being I don't need to move or scale the ScatterView item so no shadows are neccessary I just simply want to remove the rectangular box.
You can achieve this by modifying the ControlTemplate for the ScatterViewItem.
If you want to remove all the visual features of the scatterview then I guess you could get away with an empty template:
<Style TargetType="{x:Type s:ScatterViewItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type s:ScatterViewItem}">
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The above template will change all scatterview items to have a blank template, but you could give it a x:Key="YourStyleName" and set the ItemContainerStyle of the ScatterView in question to only affect that scatter view.
Please note that if you use Expression Blend, you may need to add a reference to Microsoft.Surface.Presentation.Generic.dll to do this or Blend may crash when editing the template.
You can also remove the shadow, so that the ScatterViewItem is no longer visible.
Assuming that item is your ScatterViewItem:
item.ApplyTemplate();
item.Background = new SolidColorBrush(Colors.Transparent);
item.ShowsActivationEffects = false;
Microsoft.Surface.Presentation.Generic.SurfaceShadowChrome ssc;
ssc = item.Template.FindName("shadow", item) as Microsoft.Surface.Presentation.Generic.SurfaceShadowChrome;
ssc.Visibility = Visibility.Hidden;
I am having similar Problem.
Here is my code.
<s:ScatterView>
<s:ScatterView.Items>
<s:ScatterViewItem Height="1721" Width="2169">
<Canvas >
<Path Data="M0 2728 l0 -1012 28 26 c23 21 32 24 61 17 31 -6 40 -3 75 27 38 32 99 114 92 122 -6 5 -46 -21 -46 -30 0 -15 -56 -58 -75 -58 -29 0 -105 74 -105 102 0 12 14 37 32 55 31 32 32 34 20 78 -20 74 -17 82 29 89 22 4 44 4 49 1 13 -8 23 54 11 69 -8 10 -6 17 8 30 12 11 16 25 13 41 -4 24 -3 25 24 15 25 -10 31 -9 43 9 7 12 24 21 37 21 25 0 30 10 14 26 -5 5 -7 20 -3 32 7 29 34 25 48 -6 12 -27 20 -28 38 -1 13 18 24 20 74 18 32 -2 173 -2 314 -1 l256 2 12 113 c6 61 12 191 12 287 1 96 5 182 10 191 14 27 76 61 98 54 24 -7 29 -20 37 -103 10 -106 29 -115 65 -33 24 57 70 104 95 99 10 -1 29 -25 43 -53 37 -72 66 -79 141 -38 78 44 123 50 180 25 88 -38 122 -38 197 0 64 31 75 33 193 36 77 3 145 -1 177 -9 45 -10 61 -10 115 5 135 37 121 41 253 -81 64 -59 124 -111 133 -114 27 -10 473 0 515 12 47 12 84 47 92 86 22 99 71 155 143 159 27 2 79 17 118 34 46 21 97 35 153 41 64 7 100 18 150 44 36 19 86 37 111 41 25 4 65 17 90 29 52 26 113 39 140 30 29 -9 25 -49 -10 -89 -25 -28 -29 -38 -21 -59 5 -14 15 -28 21 -32 12 -8 3 -73 -13 -94 -16 -19 17 -43 103 -76 66 -25 80 -27 188 -23 109 4 121 6 176 36 32 18 67 32 77 32 25 0 24 12 -1 35 -13 12 -20 29 -18 44 2 21 10 27 38 32 39 6 102 40 140 75 23 21 30 22 64 13 52 -14 82 -5 94 30 8 22 18 30 45 35 37 7 73 38 63 55 -9 14 -94 40 -158 47 l-58 7 0 87 c0 48 -3 90 -7 93 -3 4 -5 35 -4 70 3 73 24 102 105 142 l50 25 -2592 0 -2592 0 0 -1012z" Stroke="Black"></Path>
....
....
</Canvas>
</s:ScatterViewItem>
</s:ScatterView.Items>
</s:ScatterView>
There are so many shapes in the canvas and the size of the canvas is also much higher.
so when i run the application, The canvas doesn't get re size when i re size the ScatterViewItem. And Event the Canvas i shown outside of the ScatterViewItem.
Related
I was using svg code directly in a React component:
export const AdventurerToken = (props) => {
return (
<div style={props.style}>
<svg width="3vw" height="3vw" viewBox="0 0 99 119">
<metadata>
Created by potrace 1.15, written by Peter Selinger 2001-2017
</metadata>
<g transform="translate(0.000000,119.000000) scale(0.100000,-0.100000)"
fill={props.color} stroke="none">
<path d="M336 1174 c-10 -9 -16 -33 -16 -62 0 -26 -4 -52 -8 -59 -4 -6 -35 -17 -69 -23 -35 -7 -68 -19 -74 -26 -23 -28 50 -108 134 -145 20 -9 27 -19 27
-40 0 -23 -5 -30 -27 -35 -98 -21 -212 -74 -265 -122 -36 -32 -38 -38 -38 -92 0 -84 11 -92 134 -105 32 -3 62 -8 67 -11 11 -6 -12 -69 -50 -133 -77 -129
-114 -215 -115 -266 l-1 -50 168 -3 168 -2 57 90 c33 52 63 89 71 88 8 -2 35 -41 61 -88 l47 -85 172 -3 171 -2 0 43 c0 56 -35 151 -90 247 -86 149 -86 148
-74 160 6 6 43 14 83 17 98 8 121 26 121 97 0 62 -17 89 -84 133 -42 28 -157 74 -221 88 -29 6 -28 7 23 24 79 27 122 76 122 139 0 47 -72 102 -135 102 -18
0 -25 7 -30 33 -3 17 -13 49 -22 70 l-16 37 -138 0 c-112 0 -141 -3 -153 -16z"/>
</g>
</svg>
</div>
)
};
However Firefox doesn't accept "vw" units in sve width and height properties. Workaround would be using the svg as a source for an image element:
export const AdventurerToken = (props) => {
const color = props.color;
const adventurerSVG =
<svg width="100" height="100" viewBox="0 0 99 119">
<metadata>
Created by potrace 1.15, written by Peter Selinger 2001-2017
</metadata>
<g transform="translate(0.000000,119.000000) scale(0.100000,-0.100000)" fill={color} stroke="none">
<path d="M336 1174 c-10 -9 -16 -33 -16 -62 0 -26 -4 -52 -8 -59 -4 -6 -35 -17 -69 -23 -35 -7 -68 -19 -74 -26 -23 -28 50 -108 134 -145 20 -9 27 -19 27
-40 0 -23 -5 -30 -27 -35 -98 -21 -212 -74 -265 -122 -36 -32 -38 -38 -38 -92 0 -84 11 -92 134 -105 32 -3 62 -8 67 -11 11 -6 -12 -69 -50 -133 -77 -129
-114 -215 -115 -266 l-1 -50 168 -3 168 -2 57 90 c33 52 63 89 71 88 8 -2 35 -41 61 -88 l47 -85 172 -3 171 -2 0 43 c0 56 -35 151 -90 247 -86 149 -86 148
-74 160 6 6 43 14 83 17 98 8 121 26 121 97 0 62 -17 89 -84 133 -42 28 -157 74 -221 88 -29 6 -28 7 23 24 79 27 122 76 122 139 0 47 -72 102 -135 102 -18
0 -25 7 -30 33 -3 17 -13 49 -22 70 l-16 37 -138 0 c-112 0 -141 -3 -153 -16z"/>
</g>
</svg>
return (
<img style={{width: "10vw"}} src={adventurerSVG}/>
)
};
This does not work, as evidenced by https://codesandbox.io/s/dazzling-fire-m560j?file=/src/App.js - direct import works, import as a source of element does not. What am I doing wrong? Why is the image not loaded?
Workaround: use <div> instead of <img>.
Put svg code in a variable with 100% width and height, put variable inside with correct width / height:
export const AdventurerToken = (props) => {
const color = props.color;
const adventurerSVG =
<svg width="100%" height="100%" viewBox="0 0 99 119">
<metadata>
Created by potrace 1.15, written by Peter Selinger 2001-2017
</metadata>
<g transform="translate(0.000000,119.000000) scale(0.100000,-0.100000)" fill={color} stroke="none">
<path d="M336 1174 c-10 -9 -16 -33 -16 -62 0 -26 -4 -52 -8 -59 -4 -6 -35 -17 -69 -23 -35 -7 -68 -19 -74 -26 -23 -28 50 -108 134 -145 20 -9 27 -19 27
-40 0 -23 -5 -30 -27 -35 -98 -21 -212 -74 -265 -122 -36 -32 -38 -38 -38 -92 0 -84 11 -92 134 -105 32 -3 62 -8 67 -11 11 -6 -12 -69 -50 -133 -77 -129
-114 -215 -115 -266 l-1 -50 168 -3 168 -2 57 90 c33 52 63 89 71 88 8 -2 35 -41 61 -88 l47 -85 172 -3 171 -2 0 43 c0 56 -35 151 -90 247 -86 149 -86 148
-74 160 6 6 43 14 83 17 98 8 121 26 121 97 0 62 -17 89 -84 133 -42 28 -157 74 -221 88 -29 6 -28 7 23 24 79 27 122 76 122 139 0 47 -72 102 -135 102 -18
0 -25 7 -30 33 -3 17 -13 49 -22 70 l-16 37 -138 0 c-112 0 -141 -3 -153 -16z"/>
</g>
</svg>
return (
<div style={{width: "3vw"}}>
{adventurerSVG}
</div>
)
};
Works both in Firefox and Opera.
There are a couple of problems with your code
the SVG is not valid for use as an image because it's missing the SVG namespace declaration i.e. xmlns="http://www.w3.org/2000/svg"
you need to give the img element a data URI, not just a Node
So a working example looks like this...
import React from "react";
import ReactDOMServer from "react-dom/server";
import "./styles.css";
export default function App() {
return (
<div className="App">
{adventurerSVG}
<img src={'data:image/svg+xml,' + ReactDOMServer.renderToString(adventurerSVG)}/>
</div>
);
}
const adventurerSVG = (
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 99 119">
<metadata>
Created by potrace 1.15, written by Peter Selinger 2001-2017
</metadata>
<g
transform="translate(0.000000,119.000000) scale(0.100000,-0.100000)"
fill="red"
stroke="none"
>
<path
d="M336 1174 c-10 -9 -16 -33 -16 -62 0 -26 -4 -52 -8 -59 -4 -6 -35 -17 -69 -23 -35 -7 -68 -19 -74 -26 -23 -28 50 -108 134 -145 20 -9 27 -19 27
-40 0 -23 -5 -30 -27 -35 -98 -21 -212 -74 -265 -122 -36 -32 -38 -38 -38 -92 0 -84 11 -92 134 -105 32 -3 62 -8 67 -11 11 -6 -12 -69 -50 -133 -77 -129
-114 -215 -115 -266 l-1 -50 168 -3 168 -2 57 90 c33 52 63 89 71 88 8 -2 35 -41 61 -88 l47 -85 172 -3 171 -2 0 43 c0 56 -35 151 -90 247 -86 149 -86 148
-74 160 6 6 43 14 83 17 98 8 121 26 121 97 0 62 -17 89 -84 133 -42 28 -157 74 -221 88 -29 6 -28 7 23 24 79 27 122 76 122 139 0 47 -72 102 -135 102 -18
0 -25 7 -30 33 -3 17 -13 49 -22 70 l-16 37 -138 0 c-112 0 -141 -3 -153 -16z"
/>
</g>
</svg>
);
I am writing a program to generate permutation of a given series of numbers like
10,11,12,32,33,45,56,67
then output (which is all permutation of this series) I am storing in a file result.txt
I have to generate a binary tree from each line of input in result.txt
I know the program to create a binary tree when a user gives numbers as input but here I am having a file as an example I had initially given input as 9 numbers 87,80,65,45,32,22,109,9,6 I am storing in result.txt as follows.
87 80 65 45 32 22 109 9 6
87 65 80 45 32 22 109 9 6
87 65 45 80 32 22 109 9 6
87 65 45 32 80 22 109 9 6
87 65 45 32 22 80 109 9 6
87 65 45 32 22 109 80 9 6
87 65 45 32 22 109 9 80 6
87 65 45 32 22 109 9 6 80
65 87 45 32 22 109 9 6 80
65 45 87 32 22 109 9 6 80
65 45 32 87 22 109 9 6 80
65 45 32 22 87 109 9 6 80
65 45 32 22 109 87 9 6 80
65 45 32 22 109 9 87 6 80
65 45 32 22 109 9 6 87 80
65 45 32 22 109 9 6 80 87
45 65 32 22 109 9 6 80 87
45 32 65 22 109 9 6 80 87
45 32 22 65 109 9 6 80 87
45 32 22 109 65 9 6 80 87
45 32 22 109 9 65 6 80 87
45 32 22 109 9 6 65 80 87
45 32 22 109 9 6 80 65 87
45 32 22 109 9 6 80 87 65
32 45 22 109 9 6 80 87 65
32 22 45 109 9 6 80 87 65
32 22 109 45 9 6 80 87 65
32 22 109 9 45 6 80 87 65
32 22 109 9 6 45 80 87 65
32 22 109 9 6 80 45 87 65
32 22 109 9 6 80 87 45 65
32 22 109 9 6 80 87 65 45
22 32 109 9 6 80 87 65 45
22 109 32 9 6 80 87 65 45
22 109 9 32 6 80 87 65 45
22 109 9 6 32 80 87 65 45
22 109 9 6 80 32 87 65 45
22 109 9 6 80 87 32 65 45
22 109 9 6 80 87 65 32 45
22 109 9 6 80 87 65 45 32
109 22 9 6 80 87 65 45 32
109 9 22 6 80 87 65 45 32
109 9 6 22 80 87 65 45 32
109 9 6 80 22 87 65 45 32
109 9 6 80 87 22 65 45 32
109 9 6 80 87 65 22 45 32
109 9 6 80 87 65 45 22 32
109 9 6 80 87 65 45 32 22
9 109 6 80 87 65 45 32 22
9 6 109 80 87 65 45 32 22
9 6 80 109 87 65 45 32 22
9 6 80 87 109 65 45 32 22
9 6 80 87 65 109 45 32 22
9 6 80 87 65 45 109 32 22
9 6 80 87 65 45 32 109 22
9 6 80 87 65 45 32 22 109
6 9 80 87 65 45 32 22 109
6 80 9 87 65 45 32 22 109
6 80 87 9 65 45 32 22 109
6 80 87 65 9 45 32 22 109
6 80 87 65 45 9 32 22 109
6 80 87 65 45 32 9 22 109
6 80 87 65 45 32 22 9 109
6 80 87 65 45 32 22 109 9
80 6 87 65 45 32 22 109 9
80 87 6 65 45 32 22 109 9
80 87 65 6 45 32 22 109 9
80 87 65 45 6 32 22 109 9
80 87 65 45 32 6 22 109 9
80 87 65 45 32 22 6 109 9
80 87 65 45 32 22 109 6 9
80 87 65 45 32 22 109 9 6
now the problem is if I use a function like fgets()
#include<stdio.h>
#include<stdlib.h>
int main ()
{
FILE *fp;
char line[60];
fp=fopen("result.txt","r");
while (fgets(line,60,fp)){
puts(line);
}
fclose(fp);
}
I just want the array elements to come separately in different array elemnents with output of puts or fgets this is what I am not able to think of,
any idea of doing this as how to approach this to solve is welcome. Since I do not knew how to store the output of permutation generation in array so I thought of storing output in a file. Upto here program is fine but after this how do I read each integer of series from line in result.txt is my problem I am not able to think of any C implemented function as to do so.
In C, I need to print the number pattern in the below manner in right alignment, ie: when the double digit comes the upper single digit should adjust itself to right and so on.
int main() {
long int k = 1;
int i, j, n;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; j++) {
printf("%ld ", k);
k++;
}
printf("\n");
}
return 0;
}
required output:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54 55 `
output I get:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54 55
output required:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54 55
56 57 58 59 60 61 62 63 64 65 66
67 68 69 70 71 72 73 74 75 76 77 78
79 80 81 82 83 84 85 86 87 88 89 90 91
92 93 94 95 96 97 98 99 100 101 102 103 104 105
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
output I get:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54 55
56 57 58 59 60 61 62 63 64 65 66
67 68 69 70 71 72 73 74 75 76 77 78
79 80 81 82 83 84 85 86 87 88 89 90 91
92 93 94 95 96 97 98 99 100 101 102 103 104 105
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
You should calculate the length of the last outputted number and use the value as the field width in a printf call..
Here you are.
#include <stdio.h>
int main(void)
{
while ( 1 )
{
printf( "Enter a non-negative number (0 - exit): " );
unsigned int n;
if ( scanf( "%u", &n ) != 1 || n == 0 ) break;
unsigned int upper = n * ( n + 1 ) / 2;
int size = 0;
do { ++size; } while ( upper /= 10 );
putchar( '\n' );
for ( unsigned int i = 0, value = 0; i < n; i++ )
{
do
{
printf( "%*u ", size, ++value );
} while ( value != ( i + 1 ) * ( i + 2 ) / 2 );
putchar( '\n' );
}
putchar( '\n' );
}
return 0;
}
The program output is
Enter a non-negative number (0 - exit): 10
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54 55
Enter a non-negative number (0 - exit): 20
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54 55
56 57 58 59 60 61 62 63 64 65 66
67 68 69 70 71 72 73 74 75 76 77 78
79 80 81 82 83 84 85 86 87 88 89 90 91
92 93 94 95 96 97 98 99 100 101 102 103 104 105
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
Enter a non-negative number (0 - exit): 0
I will not help you write a code because zero effort is shown, but I can give hints via a pseudo code.
cin >> n; //desired number of rows
for (int i = 0; i < n; i++){
//generate triangle numbers
}//store the first n triangle numbers, given by n(n-1)/2
for (int i = 0; i < n; i++){
cout << i;
if (i==any triangle number){
cout << "\n"; //note that an endline is printed only at triangle numbers
}
}
Here is a simple solution that handles end of lines correctly too:
#include <stdio.h>
int main(void) {
int i, j, k, n, len;
if (scanf("%d", &n) == 1 && n > 0) {
/* compute the width of the last number */
//len = snprintf(NULL, 0, "%d", n * (n + 1) / 2);
//char buf[48]; /* large enough for 128-bit integers */
//len = sprintf(buf, "%d", n * (n + 1) / 2);
for (len = 1, k = n * (n + 1) / 2; k > 9; k /= 10)
len++;
for (i = k = 1; i <= n; i++) {
for (j = 1; j < i; j++) {
printf("%*d ", len, k++);
}
/* print the last number on the line without a trailing space */
printf("%*d\n", len, k++);
}
}
return 0;
}
#include<stdio.h>
main()
char i=13;
while(i)
{
i++;
}
printf("%d",i);
}
the out put turns out to be zero . how come does it happen
#include<stdio.h>
main()
char i=48;
if(i)
{
printf("%d",i);
}
}
this program run sucessfully and prints 48. isn't i considered a character o for which it is supposed to fail .How is i stored in the memory as a character or a number
You're missing a bracket after 'main()'. Your first code actually keeps counting up from 13, until it hits 127 (if, on your system, chars are represented as signed integers) because this is the largest positive integer for a char on such a system; then flips to -128 and keeps counting up to 0. At 0, you exit your loop, and print the result. To visualize what happens, copy this and try it out:
#include <stdio.h>
int main()
{
char i=13;
while(i){
i++;
printf("%d ", i);
}
printf("\n%d",i);
}
Output:
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 -128 -127 -126 -125 -124 -123 -122 -121 -120 -119 -118 -117 -116 -115 -114 -113 -112 -111 -110 -109 -108 -107 -106 -105 -104 -103 -102 -101 -100 -99 -98 -97 -96 -95 -94 -93 -92 -91 -90 -89 -88 -87 -86 -85 -84 -83 -82 -81 -80 -79 -78 -77 -76 -75 -74 -73 -72 -71 -70 -69 -68 -67 -66 -65 -64 -63 -62 -61 -60 -59 -58 -57 -56 -55 -54 -53 -52 -51 -50 -49 -48 -47 -46 -45 -44 -43 -42 -41 -40 -39 -38 -37 -36 -35 -34 -33 -32 -31 -30 -29 -28 -27 -26 -25 -24 -23 -22 -21 -20 -19 -18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0
The positive to negative change has to do with the IEEE representation of integers on computers. You can find many related questions on SO if you google for them.
An if statement compares the numeric value, not the ASCII character that it happens to represent. Only the numeric value 0 will result in the if failing to execute in your second example.
This question already has answers here:
Hash key as array to obtain the minimum and maximum numbers if a columns values are equal
(3 answers)
Closed 8 years ago.
I have the next file:
-38 miRNA18 8 44 dvex109349 6618 6580
35 miRNA5 21 57 dvex110330 1917 1952
26 miRNA2 27 54 dvex110362 1092 1118
-30 miRNA43 60 90 dvex110558 464 434
30 miRNA2 31 63 dvex111097 1359 1389
-30 miRNA31 43 73 dvex111146 4337 4307
-29 miRNA32 32 63 dvex111322 5680 5651
35 miRNA43 60 95 dvex111435 5612 5647
-26 miRNA43 55 80 dvex111770 723 697
-39 miRNA43 21 58 dvex112127 4928 4889
-32 miRNA2 70 102 dvex112254 1554 1522
33 miRNA17 56 89 dvex113799 2985 3018
38 miRNA17 26 64 dvex113799 2985 3023
40 miRNA17 30 70 dvex113799 2985 3025
I need to insert it into a hash, but with these parameters: the column 5 (dvex####) must be the key, and the others will be the values to this key. The idea, is group it by equal keys, and obtain the lower value of the column 6 and the maximun value of the column 7.
I think that is convenient create a hash with keys as an array, then organize it with that parameters.
The output should be:
-38 miRNA18 8 44 dvex109349 6618 6618
35 miRNA5 21 57 dvex110330 1917 1952
-38 miRNA18 8 44 dvex109349 6618 6580
35 miRNA5 21 57 dvex110330 1917 1952
26 miRNA2 27 54 dvex110362 1092 1118
-30 miRNA43 60 90 dvex110558 464 434
30 miRNA2 31 63 dvex111097 1359 1389
-30 miRNA31 43 73 dvex111146 4337 4307
-29 miRNA32 32 63 dvex111322 5680 5651
35 miRNA43 60 95 dvex111435 5612 5647
-26 miRNA43 55 80 dvex111770 723 697
-39 miRNA43 21 58 dvex112127 4928 4889
-32 miRNA2 70 102 dvex112254 1554 1522
33 miRNA17 26 70 dvex113799 2985 3025 #note this result is a group.
I'm very interesting because the solution is based in a file with different columns...
using a regex or split extract columns 6 (and maybe 6,7) to a scalar.
store the line into a nested hash.
$data1{$v5}{$v6}=$_;
$data2{$v5}{$v7}=$_;
List::Util will help with max/min
use List::Util qw[min max];
foreach $v5 (sort keys %data) {
$val6=min(keys $data1{$v5});
$val7=max(keys $data2{$v5});
now generate your output line as you desire.
}