|
Posted by onlineviewer on July 23, 2006, 2:00 pm
Please log in for more thread options
Hello All,,
I need some assistance please, i've been fussing with this for a while
but i'm stuck.
What i need here is, while my Style column in my .csv file continues to
be the same number, take the corresponding number in the Size column,
and sort it ,separated by a pipe. for as long as the number in the
Style column continues to be the same. So the Style column contains
numbers like 123456, and the Size column are numbers like 8, 9.5, 7
etc...Before and After should look like this:
Before:
123456 8
123456 10
123456 8.5
838493 12
838493 10
838494 9
After:
123456 8|8.5|10|11
838493 9|10|12
etc etc....
I have the following so far which isn't much, I've
only put the values from the 2 columns into separate variables.
Any suggestions please, i'm still pretty at this kind of stuff,,.
Thanks again,
$csv_fh = Tie::Handle::CSV->new('myfile.csv');
while (<$csv_fh>){
$StyleField = ( scalar <$csv_fh> )->;
$SizeField = ( scalar <$csv_fh> )->;
}
|
|
Posted by Mumia W. on July 23, 2006, 5:16 pm
Please log in for more thread options
On 07/23/2006 01:00 PM, onlineviewer wrote:
> Hello All,,
>
> I need some assistance please, i've been fussing with this for a while
> but i'm stuck.
>
> What i need here is, while my Style column in my .csv file continues to
> be the same number, take the corresponding number in the Size column,
> and sort it ,separated by a pipe. for as long as the number in the
> Style column continues to be the same. So the Style column contains
> numbers like 123456, and the Size column are numbers like 8, 9.5, 7
> etc...Before and After should look like this:
>
> Before:
> 123456 8
> 123456 10
> 123456 8.5
> 838493 12
> 838493 10
> 838494 9
>
> After:
> 123456 8|8.5|10|11
> 838493 9|10|12
>
> etc etc....
>
> I have the following so far which isn't much, I've
> only put the values from the 2 columns into separate variables.
> Any suggestions please, i'm still pretty at this kind of stuff,,.
> Thanks again,
>
> $csv_fh = Tie::Handle::CSV->new('myfile.csv');
>
> while (<$csv_fh>){
> $StyleField = ( scalar <$csv_fh> )->;
> $SizeField = ( scalar <$csv_fh> )->;
> }
>
You could create a hash to store the styles as keys and the
sizes as values; then you'd push each size into the hash
(using autovivication) as it's found:
my %hash;
...
push @}, $SizeField;
|
|
Posted by onlineviewer on July 23, 2006, 10:44 pm
Please log in for more thread options
Thanks for the sponse,
I'm not sure where in my script this push function would go, i'm
confused.
I see what needs to happens, but i'm not sure how to get
there,,.Suggestions
please,,.
$csv_fh = Tie::Handle::CSV->new('csvfile.csv');
$\ = "|";
while(<$csv_fh>){
$StyleField = ( scalar <$csv_fh> )->;
$SizeField = ( scalar <$csv_fh> )->;
push @}, $SizeField;
}
Mumia W. wrote:
> On 07/23/2006 01:00 PM, onlineviewer wrote:
> > Hello All,,
> >
> > I need some assistance please, i've been fussing with this for a while
> > but i'm stuck.
> >
> > What i need here is, while my Style column in my .csv file continues to
> > be the same number, take the corresponding number in the Size column,
> > and sort it ,separated by a pipe. for as long as the number in the
> > Style column continues to be the same. So the Style column contains
> > numbers like 123456, and the Size column are numbers like 8, 9.5, 7
> > etc...Before and After should look like this:
> >
> > Before:
> > 123456 8
> > 123456 10
> > 123456 8.5
> > 838493 12
> > 838493 10
> > 838494 9
> >
> > After:
> > 123456 8|8.5|10|11
> > 838493 9|10|12
> >
> > etc etc....
> >
> > I have the following so far which isn't much, I've
> > only put the values from the 2 columns into separate variables.
> > Any suggestions please, i'm still pretty at this kind of stuff,,.
> > Thanks again,
> >
> > $csv_fh = Tie::Handle::CSV->new('myfile.csv');
> >
> > while (<$csv_fh>){
> > $StyleField = ( scalar <$csv_fh> )->;
> > $SizeField = ( scalar <$csv_fh> )->;
> > }
> >
>
> You could create a hash to store the styles as keys and the
> sizes as values; then you'd push each size into the hash
> (using autovivication) as it's found:
>
> my %hash;
> ...
> push @}, $SizeField;
|
|
Posted by onlineviewer on July 24, 2006, 10:39 am
Please log in for more thread options
Hello Again,
If anyone has any suggestions for me please,,.
I'm at this point:
while(<$csv_fh>){
$SizeField = ( scalar <$csv_fh> )->;
$StyleField = ( scalar <$csv_fh> )->;
push @}, $SizeField;
print "$StyleField => $SizeField\n";
which produces this output:
123345 => 8.5
123345 => 10.5
555443 => 12
555443 => 7
555443 => 8.5
I need the output to look like this:
123345 => 8.5|10.5
555443 => 7|8.5|12
onlineviewer wrote:
> Thanks for the sponse,
>
> I'm not sure where in my script this push function would go, i'm
> confused.
> I see what needs to happens, but i'm not sure how to get
> there,,.Suggestions
> please,,.
>
> $csv_fh = Tie::Handle::CSV->new('csvfile.csv');
> $\ = "|";
>
> while(<$csv_fh>){
> $StyleField = ( scalar <$csv_fh> )->;
> $SizeField = ( scalar <$csv_fh> )->;
> push @}, $SizeField;
> }
>
>
> Mumia W. wrote:
> > On 07/23/2006 01:00 PM, onlineviewer wrote:
> > > Hello All,,
> > >
> > > I need some assistance please, i've been fussing with this for a while
> > > but i'm stuck.
> > >
> > > What i need here is, while my Style column in my .csv file continues to
> > > be the same number, take the corresponding number in the Size column,
> > > and sort it ,separated by a pipe. for as long as the number in the
> > > Style column continues to be the same. So the Style column contains
> > > numbers like 123456, and the Size column are numbers like 8, 9.5, 7
> > > etc...Before and After should look like this:
> > >
> > > Before:
> > > 123456 8
> > > 123456 10
> > > 123456 8.5
> > > 838493 12
> > > 838493 10
> > > 838494 9
> > >
> > > After:
> > > 123456 8|8.5|10|11
> > > 838493 9|10|12
> > >
> > > etc etc....
> > >
> > > I have the following so far which isn't much, I've
> > > only put the values from the 2 columns into separate variables.
> > > Any suggestions please, i'm still pretty at this kind of stuff,,.
> > > Thanks again,
> > >
> > > $csv_fh = Tie::Handle::CSV->new('myfile.csv');
> > >
> > > while (<$csv_fh>){
> > > $StyleField = ( scalar <$csv_fh> )->;
> > > $SizeField = ( scalar <$csv_fh> )->;
> > > }
> > >
> >
> > You could create a hash to store the styles as keys and the
> > sizes as values; then you'd push each size into the hash
> > (using autovivication) as it's found:
> >
> > my %hash;
> > ...
> > push @}, $SizeField;
|
|
Posted by Mumia W. on July 24, 2006, 12:53 pm
Please log in for more thread options
On 07/24/2006 09:39 AM, onlineviewer wrote:
> Hello Again,
>
> If anyone has any suggestions for me please,,.
> I'm at this point:
>
> while(<$csv_fh>){
> $SizeField = ( scalar <$csv_fh> )->;
> $StyleField = ( scalar <$csv_fh> )->;
> push @}, $SizeField;
> print "$StyleField => $SizeField\n";
> [...]
Your well-written while loop puts some pretty interesting
things into %MYHASH. Have you taken a look into %MYHASH lately?
Typically what you do when programming is to write some code
that fills a data structure with data. Then, because there are
many opportunities to write bugs that mess up the data, you
print out the data structure to make sure that it's right.
So naturally, after putting "push @{$MYHASH..." into your
while loop, you'd print the contents of %MYHASH (after the
while loop) to make sure the data is all there. I happen to
think that it is.
The lazy person's (my) way of printing a complex data
structure is to use the Data::Dumper module. Read the doc on
Data::Dumper: "perldoc Data::Dumper". Use Data::Dumper to
display the contents of %MYHASH.
|
| Similar Threads | Posted | | Tie::Handle::CSV and newlines | February 1, 2007, 1:47 am |
| Archive::Tar and how to handle *.bz2 archives? | September 13, 2005, 3:18 pm |
| help on how to use PERL to do a "postmessage" to a windows handle | January 16, 2005, 12:10 pm |
| XML::Simple doesn't handle shorthand notation?? | January 19, 2005, 6:09 am |
| Handle multiple input date formats? | September 11, 2004, 11:56 am |
| HTML::Mason handle nonexistent directories | June 14, 2005, 12:45 pm |
| Need to handle the NNTP connection timeout in my code | February 8, 2007, 4:51 am |
| How can I make HTTP::Request handle gzipped content? | September 3, 2004, 2:11 am |
| Can't locate object method "blocking" via package "IO::Handle" | June 20, 2005, 8:38 am |
| How to handle input and output of a program executed by System function in perl | July 18, 2004, 2:31 pm |
|