Ask a Question related to PERL Modules, Design and Development.
-
onlineviewer #1
Tie::Handle::CSV Help...
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> )->{'Style'};
$SizeField = ( scalar <$csv_fh> )->{'Size'};
}
onlineviewer Guest
-
Can I Handle Error 404 JUST Using ASP ?
understand that through IIS you can implement custom error messages, but since we are in hosted environment, we need to implement custom error... -
handle the IE.
Hello, I need to show full screen, when IE is shown. Can I handle the appearence of IE by some flash commands ? Also, can I hanlde the html,... -
[PHP] Not sure of the best way to handle a problem
Actually it does have to do with php.One of my main questions was also about whether it was best to use the script from the command-line or from... -
I cannot handle Tables!
I get very surprized when I set everything accurately and corrently in Dremweaver and I get a bad result in the browser! How is this possible to set... -
handle file > 2GB
Hi there, Anyone know how to handle file size > 2GB in SUN? I called stat but it fail with EOVERFLOW if the file > 2GB. TIA -
Mumia W. #2
Re: Tie::Handle::CSV Help...
On 07/23/2006 01:00 PM, onlineviewer wrote:
You could create a hash to store the styles as keys and the> 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> )->{'Style'};
> $SizeField = ( scalar <$csv_fh> )->{'Size'};
> }
>
sizes as values; then you'd push each size into the hash
(using autovivication) as it's found:
my %hash;
...
push @{$hash{$StyleField}}, $SizeField;
Mumia W. Guest
-
onlineviewer #3
Re: Tie::Handle::CSV Help...
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> )->{'Style'};
$SizeField = ( scalar <$csv_fh> )->{'Size'};
push @{$hash{$StyleField}}, $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> )->{'Style'};
> > $SizeField = ( scalar <$csv_fh> )->{'Size'};
> > }
> >
> 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 @{$hash{$StyleField}}, $SizeField;onlineviewer Guest
-
onlineviewer #4
Re: Tie::Handle::CSV Help...
Hello Again,
If anyone has any suggestions for me please,,.
I'm at this point:
while(<$csv_fh>){
$SizeField = ( scalar <$csv_fh> )->{'Size'};
$StyleField = ( scalar <$csv_fh> )->{'Style'};
push @{$MYHASH{$StyleField}}, $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> )->{'Style'};
> $SizeField = ( scalar <$csv_fh> )->{'Size'};
> push @{$hash{$StyleField}}, $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> )->{'Style'};
> > > $SizeField = ( scalar <$csv_fh> )->{'Size'};
> > > }
> > >
> > 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 @{$hash{$StyleField}}, $SizeField;onlineviewer Guest
-
Mumia W. #5
Re: Tie::Handle::CSV Help...
On 07/24/2006 09:39 AM, onlineviewer wrote:
Your well-written while loop puts some pretty interesting> Hello Again,
>
> If anyone has any suggestions for me please,,.
> I'm at this point:
>
> while(<$csv_fh>){
> $SizeField = ( scalar <$csv_fh> )->{'Size'};
> $StyleField = ( scalar <$csv_fh> )->{'Style'};
> push @{$MYHASH{$StyleField}}, $SizeField;
> print "$StyleField => $SizeField\n";
> [...]
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.
Mumia W. Guest
-
Jim Gibson #6
Re: Tie::Handle::CSV Help...
In article <1153751991.227975.112520@p79g2000cwp.googlegroups .com>,
onlineviewer <lancerset@gmail.com> wrote:
> Hello Again,
>
> If anyone has any suggestions for me please,,.
> I'm at this point:
>
> while(<$csv_fh>){
> $SizeField = ( scalar <$csv_fh> )->{'Size'};
> $StyleField = ( scalar <$csv_fh> )->{'Style'};
> push @{$MYHASH{$StyleField}}, $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
#!/usr/local/bin/perl
use strict;
use warnings;
my %myhash = (
'123345' => [ 8.5, 10.5 ],
'555443' => [ 12, 7, 8.5 ]
);
for my $key ( sort keys %myhash ) {
print "$key => ", join('|',sort {$a<=>$b} @{$myhash{$key}} ),"\n";
}
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
[url]http://www.usenet.com[/url]
Jim Gibson Guest



Reply With Quote

