arrays problem
Hi All, Here is my problem with the script below: I can access each item from each line. But I got stuck trying to figure out how to access each hobbies/sports lines!! I need to be able to get data from for instance: $ssns{$ssn}{hobbies}[0][2] which should yield H3 $ssns{$ssn}{hobbies}[3][0] to get HG. (data file is at bottom of message) In a loop: for ssn = xyz: Hobbies are: line 0, row 0 : = line 0, row 1 : = line 1, row 0: = line 1, row 1: = and so on. script is below use strict; use Data::Dumper; $Data::Dumper::Indent=1; # print &Data::Dumper::Dumper($var); my %ssns; while () { # chomp; # remove \n next if /^\s*$/;# skip blanke lines my @line = split /\s*,\s*/, $_; my $key = $line[0]; my $ssn = $line[1]; # Name, SSN, , if ($key =~ /^Name/i) { $ssns{$ssn}{name} = $line[2]; $ssns{$ssn}{number} = $line[3]; } # Sports, SSN, , ... if ($key =~ /^Sports/i) { push @{$ssns{$ssn}{sports}}, @line[2 .. $#line]; } # Hobbies, SSN, , ... if ($key =~ /^Hobbies/i) { push @{$ssns{$ssn}{hobbies}}, @line[2 .. $#line]; } } #print Data::Dumper->Dump([\%ssns], [qw(ssns)]);# dump hash # print results foreach (sort keys %ssns) { print "For ssn $_:\n"; print " Sports are:\n"; foreach (sort @{$ssns{$_}{sports}}) { print "$_ "; } print "\n"; print " Hobbies are:\n"; foreach (sort @{$ssns{$_}{hobbies}}) { print "$_ "; } print "\n"; print "\n"; } exit 0; __DATA__ Name ,123-43-4352, JX, 1234 Sports,123-43-4352, SKI, BaseBall, swimming Hobbies, 123-43-4352, H1,H2, H3 Hobbies, 123-43-4352, HH, HHH, 2 Hobbies,123-43-4352, H1,H43 Name ,223-63-9352, JX, 1234 Sports,223-63-9352, SKI, BaseBall, swimming Hobbies, 223-63-9352, H1,H2, H3 Hobbies, 223-63-9352, HH, HHH, 2 Hobbies,223-63-9352, H1,H43 Hobbies,223-63-9352, HG, HG, HGFR __END__ I.S __ Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/
Re: arrays problem
Michael, Thanks for taking the time to solve this problem. Of course those are not real ssn numbers. I tried your suggestion: if ($key =~ /^Hobbies/i) { push @{$ssns{$ssn}{hobbies}}, [@line[2 .. $#line]]; } } # print results print "\n TEST: $ssns{'123-43-4352'}{'hobbies'}[2][2]\n"; It came out with no results and down below in the foreach loop: It printed: Hobbies are: ARRAY(0xca6840) ARRAY(0xca6828) ARRAY(0xca67f8) ARRAY(0xca67a4) Did I miss/skip something in the code? Regards I.S Michael Fowler <[EMAIL PROTECTED]> wrote: > > On Wed, Jun 13, 2001 at 04:09:29PM -0400, F.H wrote: > [snip] > > $ssns{$ssn}{hobbies}[0][2] which should yield H3 > > $ssns{$ssn}{hobbies}[3][0] to get HG. > [snip] > > > if ($key =~ /^Hobbies/i) { > > push @{$ssns{$ssn}{hobbies}}, @line[2 .. $#line]; > > } > > From this, your data structure is: > > %ssns = ( > '123-43-4352' => { > 'hobbies' => [qw( > JX 1234 SKI BaseBall swimming H1 H2 H3 HH HHH 2 H1 H43 > )], > ... > }, > > ... > ); > > But you're trying to access it as: > > $ssns{'123-43-4352'}{'hobbies'}[0][2]; > > You have one index too many. To get 'H3' you'd use: > > $ssns{'123-43-4352'}{'hobbies'}[7]; > > > If you want to preserve the line numbers you need to push an array > reference: > > if ($key =~ /^Hobbies/i) { > push @{$ssns{$ssn}{hobbies}}, [@line[2 .. $#line]]; > } > > Your data structure would then look like this: > > %ssns = ( > '123-43-4352' => { > 'hobbies' => [ > [qw(JX 1234 )], > [qw(SKI BaseBall swimming)], > [qw(H1 H2 H3 )], > [qw(HH HHH 2 )], > [qw(H1 H43 )], > )], > ... > }, > > ... > ); > > > Then you'd be able to access 'H3' as: > > $ssns{'123-43-4352'}{'hobbies'}[2][2]; > > > You have commented lines in your script for printing out the data structure > using Data::Dumper. This is a good idea, and ideal for determining why your > accesses aren't getting the data you want. > > > > > __DATA__ > > Name ,123-43-4352, JX, 1234 > > Sports,123-43-4352, SKI, BaseBall, swimming > > Hobbies, 123-43-4352, H1,H2, H3 > > Hobbies, 123-43-4352, HH, HHH, 2 > > Hobbies,123-43-4352, H1,H43 > > > > Name ,223-63-9352, JX, 1234 > > Sports,223-63-9352, SKI, BaseBall, swimming > > Hobbies, 223-63-9352, H1,H2, H3 > > Hobbies, 223-63-9352, HH, HHH, 2 > > Hobbies,223-63-9352, H1,H43 > > Hobbies,223-63-9352, HG, HG, HGFR > > I sincerely hope these aren't real social security numbers. > > > Michael > -- > Administrator www.shoebox.net > Programmer, System Administrator www.gallanttech.com > -- > __ Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/
Re: arrays problem
Hi, Let me just clarify that in this loop where it doesn't work: foreach $i ( 0 .. $#{ $ssns{$ssn}{hobbies} } ) { print " $ssns{$ssn}{hobbies}[$i]"; } I need to be able to access through maybe a multidemensional array each elemnt of the hobbies. Thanks I.S [EMAIL PROTECTED] (F.H) wrote: > > > Michael, > Thanks for taking the time to solve this problem. Of course those are not real ssn >numbers. > I tried your suggestion: > > > if ($key =~ /^Hobbies/i) { > push @{$ssns{$ssn}{hobbies}}, [@line[2 .. $#line]]; > } > } > > # print results > print "\n TEST: $ssns{'123-43-4352'}{'hobbies'}[2][2]\n"; > It came out with no results and down below in the foreach loop: > It printed: > Hobbies are: > ARRAY(0xca6840) ARRAY(0xca6828) ARRAY(0xca67f8) ARRAY(0xca67a4) > > Did I miss/skip something in the code? > Regards > > I.S > > Michael Fowler <[EMAIL PROTECTED]> wrote: > > > > On Wed, Jun 13, 2001 at 04:09:29PM -0400, F.H wrote: > > [snip] > > > $ssns{$ssn}{hobbies}[0][2] which should yield H3 > > > $ssns{$ssn}{hobbies}[3][0] to get HG. > > [snip] > > > > > if ($key =~ /^Hobbies/i) { > > > push @{$ssns{$ssn}{hobbies}}, @line[2 .. $#line]; > > > } > > > > From this, your data structure is: > > > > %ssns = ( > > '123-43-4352' => { > > 'hobbies' => [qw( > > JX 1234 SKI BaseBall swimming H1 H2 H3 HH HHH 2 H1 H43 > > )], > > ... > > }, > > > > ... > > ); > > > > But you're trying to access it as: > > > > $ssns{'123-43-4352'}{'hobbies'}[0][2]; > > > > You have one index too many. To get 'H3' you'd use: > > > > $ssns{'123-43-4352'}{'hobbies'}[7]; > > > > > > If you want to preserve the line numbers you need to push an array > > reference: > > > > if ($key =~ /^Hobbies/i) { > > push @{$ssns{$ssn}{hobbies}}, [@line[2 .. $#line]]; > > } > > > > Your data structure would then look like this: > > > > %ssns = ( > > '123-43-4352' => { > > 'hobbies' => [ > > [qw(JX 1234 )], > > [qw(SKI BaseBall swimming)], > > [qw(H1 H2 H3 )], > > [qw(HH HHH 2 )], > > [qw(H1 H43 )], > > )], > > ... > > }, > > > > ... > > ); > > > > > > Then you'd be able to access 'H3' as: > > > > $ssns{'123-43-4352'}{'hobbies'}[2][2]; > > > > > > You have commented lines in your script for printing out the data structure > > using Data::Dumper. This is a good idea, and ideal for determining why your > > accesses aren't getting the data you want. > > > > > > > > > __DATA__ > > > Name ,123-43-4352, JX, 1234 > > > Sports,123-43-4352, SKI, BaseBall, swimming > > > Hobbies, 123-43-4352, H1,H2, H3 > > > Hobbies, 123-43-4352, HH, HHH, 2 > > > Hobbies,123-43-4352, H1,H43 > > > > > > Name ,223-63-9352, JX, 1234 > > > Sports,223-63-9352, SKI, BaseBall, swimming > > > Hobbies, 223-63-9352, H1,H2, H3 > > > Hobbies, 223-63-9352, HH, HHH, 2 > > > Hobbies,223-63-9352, H1,H43 > > > Hobbies,223-63-9352, HG, HG, HGFR > > > > I sincerely hope these aren't real social security numbers. > > > > > > Michael > > -- > > Administrator www.shoebox.net > > Programmer, System Administrator www.gallanttech.com > > -- > > > __ > Get your own FREE, personal Netscape Webmail account today at >http://webmail.netscape.com/ > __ Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/
deep hash
Hi All, I am trying to display some data as follows: City: Chicago Street: Main People: John Doe 1 John Doe 2 J.D 3 City: L.A Street and so on...for the other states my %state; While ($line = ){ ... push @{$state{$city}{$street}{people}}, @line[5..$#line]; } Now the problem: foreach $city (keys %state) { print" City: $city\n"; foreach $i (0 .. $#{$state{$city}{$street}}{ print" Street: $street\n"; foreach $j (0 .. $#{$state{$city}{$street}{people}{ print" $_\n"; } } } This is where I get stuck. I'd appreciate if someone can help. I.S __ Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/
Hash of arrays
Hi All, I just wonder why the if condition is always true regardless of the value of the array AB. @AB = [1,2], and $i gets printed even for values not inlcuded in array AB. foreach $i ( 0 .. $#{ $testsec{'AB'} } ) { if ($testsec{'AB'}[$i] = "6543"){ # always true print "$i\n"; } else { last ;} print " $testsec{'AB'}[$i]\n"; } } I appreciate if someone can help. I.S __ Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/
data matching
Hi all, I am trying to skip any line in my input file that doesn't have a city with a street named 'MAIN'. I am matching record[3] in my input file with a $city (array) from a hash (%state) that I got from another file. The problem is that @city contains more than one element! while ($line = ){ $city = $record[3] ; for ($i = 0; $i <= $#{ $state{$city}; $i ++ ) { next if$state{$city}[$i] ne "MAIN" } ... } @city is an array of streets can be = ['MAIN', 'MAIN1','BROADWAY','PARK'], I want to match Thanks for your help I.S __ Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/
data matching
Hi all, I am trying to skip any line in my input file that doesn't have a city with a street named 'MAIN'. I am matching record[3] in my input file with a $city (array) from a hash (%state) that I got from another file. The problem is that @city contains more than one element! while ($line = ){ $city = $record[3] ; for ($i = 0; $i <= $#{ $state{$city}; $i ++ ) { next if$state{$city}[$i] ne "MAIN" } ... } @city is an array of streets can be = ['MAIN', 'MAIN1','BROADWAY','PARK'], I want to match Thanks for your help I.S __ Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/
Re: data matching
[EMAIL PROTECTED] wrote: > > > --- "F.H" <[EMAIL PROTECTED]> wrote: > > Hi all, > > Hi. =o) > > > I am trying to skip any line in my input file that doesn't have a > > city with a street named 'MAIN'. I am matching record[3] in my input > > file with a $city (array) from a hash (%state) that I got from > > another file. The problem is that @city contains more than one > > element! > > a $city (array) ??? > > What do you mean? Sorry for the confusion, But I meant city is an array and at the same time an element of the hash %state. > > while ($line = ){ > > > > It might help to see some of the ellipsed code > Nothing much: for ($line) { # get rid of quotes s/^"|"$//g; s/\s*","\s*|,"*/,/g; } > > $city = $record[3] ; > > for ($i = 0; $i <= $#{ $state{$city}; $i ++ ) { > > Never use the > for( ; ; ) { } > construct in Perl without a significant and compelling reason. > foreach is virtually always better for lots of reasons. Try: > > for my $i ( 0 .. $#{ $state{$city} ) { > > > next if $state{$city}[$i] ne "MAIN" > > Is that next supposed to advance the while loop? > Because I think it's an expensive no-op that just advances the for > loop. I've tried that as well, and the purpose is to skip any line where the city doesn't have street = 'MAIN' > Label the while like this: > > READ: while($line=) { > > and then specify which loop is being advanced with > > next READ if > > > } > > Hmm... > maybe: > READ: while($line=) { > my %lookup = (); > @lookup{@state{$city}} = 1 .. scalar(@state{$city}); > next READ unless $lookup{MAIN}; > # it's there, so do whatever code... > > > } > > I haven't tested this, and something about it feels funny > But it's a start. =o) > > __ > Do You Yahoo!? > Get personalized email addresses from Yahoo! Mail > http://personal.mail.yahoo.com/ > __ Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/
Re: data matching
Hello Here is my script, I am missing something. All I am trying to do is to skip LA and BURLINGTON lines, because they are missing 'MAIN'. Thanks. I.S my %state; %state = ( CHICAGO => ["MAIN", "BROADWAY", "OAK"], LA => ["DELTA", "GAMMA"], BOSTON => ["FIRST", "MAIN"], BURLINGTON => ["SECOND", "ONE"], SEATTLE => ["GREAT","MAIN"], ); SWITCH:{ while ($line = ){ #next if /^\s*$/; @line = split /\s*,\s*/, $line; $city = $line[3]; #print @line; #print "CITY : $city\n"; foreach $street (@{ $state{$city} } ){ print $street, "\n"; if ( $street ne "MAIN"){ next SWITCH; } } } } __DATA__ STATE ,IL, SDW,CHICAGO STATE,CA, SFD,LA STATE, MA, FDR,BOSTON STATE, CT,FGD,BURLINGTON STATE, WA, SDF,SEATTLE __END__ Michael Fowler <[EMAIL PROTECTED]> wrote: > > On Thu, Jun 28, 2001 at 02:34:31PM -0700, Paul wrote: > > > $city = $record[3] ; > > > for ($i = 0; $i <= $#{ $state{$city}; $i ++ ) { > > > > Never use the > > for( ; ; ) { } > > construct in Perl without a significant and compelling reason. > > foreach is virtually always better for lots of reasons. Try: > > > > for my $i ( 0 .. $#{ $state{$city} ) { > > Well, you make a good point that one should use foreach, but then you use it > in almost identical way as the for loop. If you were to use it this way, > you might as well use a for loop. The most readable and idiomatic way to do > this is: > > foreach my $street (@{ $state{$city} }) { > ... if $street ne "MAIN"; > } > > You should try to avoid the foreach (0 .. $#array) form; that list has to go > into memory somewhere, and it's just a more verbose way of saying foreach > (@array). > > Otherwise, that's some good advice. > > > Michael > -- > Administrator www.shoebox.net > Programmer, System Administrator www.gallanttech.com > -- > __ Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/
Re: data matching
Michael Fowler <[EMAIL PROTECTED]> wrote: > > You probably shouldn't be using a bare block as a looping construct. What > is the intent of your code, what do you want it to do if $street eq 'MAIN' > or $street ne 'MAIN'? > Sorry I have not been quite clear about what I want to get: use strict; my %state = ( CHICAGO => [qw(MAIN BROADWAYOAK)], LA => [qw(DELTAGAMMA )], BOSTON => [qw(FIRSTMAIN )], BURLINGTON => [qw(SECOND ONE)], SEATTLE => [qw(GREATMAIN )], ); CITY:while (my $line = ){ my @line = split /\s*,\s*/, $line; my $city = $line[3]; foreach my $city (keys %state) { foreach my $street (@{ $state{$city} } ){ if ($street ne 'MAIN'){ next ; } } next CITY; } print "$line\n"; } __DATA__ STATE ,IL, SDW,CHICAGO STATE,CA, SFD,LA STATE, MA, FDR,BOSTON STATE, CT,FGD,BURLINGTON STATE, WA, SDF,SEATTLE __END__ I want my output to be (print only lines where city/ street <> 'MAIN' : STATE ,IL, SDW,CHICAGO STATE, MA, FDR,BOSTON STATE, WA, SDF,SEATTLE I.S __ Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/
encrypt password
Hi, Anyone know is there is a way(Perl built in function etc..) to encrypt a line in a configuration file. something like this: password= test_password user= test_user I want to be able to encrypt the password line only, but be able to read from it. Also another question: Is it NOT recomended to have a for loop nested in a 'if' statement or it doesn't really matter. Thanks I.S __ Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/
string position
Hi, I'd like to be able to print a string at a specific location . Is there any function that does that. $test = "abcd'; I want to print $test at position 20-25. I appreciate if someone can help Thanks I.S __ Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/
Re: string position
I meant, counting characters from left to right, $test will occupy charcater position 20 through 25, the print out will look like this. ,abcd , there are other string variables before and after that $test of course. Greg Meckes <[EMAIL PROTECTED]> wrote: > > You can try: > > $test = "abcd"; > > $test = sprintf "%24s" , $test; > > > Greg > > __ > Do You Yahoo!? > Get personalized email addresses from Yahoo! Mail > http://personal.mail.yahoo.com/ > __ Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/
Re: DBI fatal error message
C.J, I am able to connect successfully to the sybase SQL server. $dbh = DBI->connect("dbi:Sybase:server=$server;loginTimeout=240", $userID, $pass) my problem is that eventhough I have set a timeout parameter I still get that message pretty regularly!!! I set it to a higher value and still the same. Regards I.S "C.J. Collier" <[EMAIL PROTECTED]> wrote: > > Heya I.S, > > I think we need to be a bit more specific. You're not giving us any > information (even wrong information) about how you connect to the > database. We don't know for sure whether you're passing the right > arguments. I am going to assume you're using MySQL, as it's a common > database engine, and I know it better than others ;) > > so here's some code (mostly from perldoc DBD::mysql) > > use DBI; > > $driver = "mysql"; > my $hostname = 'db.foo.com'; > my $database = 'mydb'; > my $dsn = "DBI:$driver:database=$database;host=$hostname"; > > my $username = 'user'; > my $password = 'pass'; > my $dbh = DBI->connect($dsn, $username, $password); > > my $table = "mydb"; # this bothers me. do you really mean it? > > my $query = "SELECT ? ? from $table"; #?s replaced in the execute() call > > my $sth = $dbh->prepare( $query ) > or die "Can't prepare statement: $DBI::errstr"; > > my $rc = $sth->execute("field1", "field2") > or die "Can't execute statement: $DBI::errstr"; > > while (($field1, $field2) = $sth->fetchrow_array) { > > > } > die $sth->errstr if $sth->err > > > that might clean things up for you a bit. I'm kinda' in a hurry and > didn't get a chance to test this. If you could let us know how you're > connecting (and maybe try a different approach), we might be able to > give you a bit more information. > > Good luck, > > C.J. > > On Thu, 12 Jul 2001, F.H wrote: > > > Hi ALL, > > I get pretty much all the time this fatal error message when I try to connect to a >remote sql database. But when I run the perl script again, it runs just fine. > > Anyone knows why this is happening and how to overcome it? > > code looks like this: > > #I tried sleep 5; and didn't do much > > my $dbh = DBI->connect( > || die "Can't connect to $data_source: $DBI::errstr"; > > $dbh->do("use mydb"); > > > > my $sth = $dbh->prepare( q{ > > SELECT field1 field2 from mydb > > }) || die "Can't prepare statement: $DBI::errstr"; > > > > > > my $rc = $sth->execute > > || die "Can't execute statement: $DBI::errstr"; > > > > while (($field1, $field2) = $sth->fetchrow_array) { > > > > > > } > > die $sth->errstr if $sth->err > > > > error: > > > > DBI->connect(server=OMEGA) failed: OpenClient message: LAYER = (5) ORIGIN = > > (3) SEVERITY = (5) NUMBER = (6) > > Message String: ct_connect(): network packet layer: internal net library error: > > Net-Library operation terminated due to disconnect > > at data.pl line 13 > > Can't connect to : OpenClient message: LAYER = (5) ORIGIN = (3) SEVERITY = (5) N > > UMBER = (6) > > Message String: ct_connect(): network packet layer: internal net library error: > > Net-Library operation terminated due to disconnect > > > > Thanks > > > > > > I.S > > __ > > Get your own FREE, personal Netscape Webmail account today at >http://webmail.netscape.com/ > > > > __ Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/
date
Hi, Does anyone know how to get a difference between 2 dates. For instance something like (07/12/01 - 07/13/01) that would get me 1. Thanks in advance I.S __ Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
error messages
Hi, I am just wondering if there is a way thru an API or others to display a perl script error messages in a Powerbuilder/VB application that calls this perl script. Any help is appreciated I.S __ Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
sprintf question
Hi, Anybody know the right syntax to left justify a string with zeros using sprintf ot any other function? $test = "mytest"; $test = sprintf "0%24s", $test; print "test"; I am getting only one zero. Thanks for your help. I.S __ Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Date problem
Hi, does anyone know how to convert a date from mmddyy to mmdd? so 010201 becomes 01022001 Thanks for your help I.S __ Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/ Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
input output append
HI, anyone knows the right syntax for reading and writing (appending) to a file. I tried this and it didn't seem to work open (FH,"+< file.txt" ) Thanks I.S __ Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/ Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
sort
Hi there, I am trying to sort on cities but it doesn't seem to yield the right sort: here is my code snippet: foreach $country ( keys %world){ foreach $city ( sort keys %{$world{$country}}) { foreach my $street ( keys %{$world{$country}{$city}} ANybody know what's wrong with this Thanks I.S __ Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/ Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
arguments with a module
Hi there, Can you use in a perl script a module with an argument. something like use mymodule -myargument; I get this message: "-myargument" is not exported bt the mymodule module. I tried in the module this @mymodule::EXPORT = qw(myargument ) and still it didn't work. I'd appreciate any suggestion I.S __ Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/ Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Re: arguments with a module
what I mean by argument is a switch/option that I pass to the module that I call whithin my main perl script. Yes I have those line in my module: >use vars qw( @EXPORT, @ISA ); >@EXPORT = qw( function_name ); >@ISA = qw( Exporter ); >require Exporter the module is so long that is not worth posting over here. All I need is to be able to pass an argument/switch to it, in my case is a file name. so I need to have something like use mymodule -myargument= I hope I am a little clearer this time. Thanks I.S Troy Denkinger <[EMAIL PROTECTED]> wrote: >On Thursday 16 August 2001 16:16, F.H wrote: >> Hi there, >> Can you use in a perl script a module with an argument. something like >> use mymodule -myargument; >> >> I get this message: "-myargument" is not exported bt the mymodule module. >> I tried in the module this >> @mymodule::EXPORT = qw(myargument ) >> and still it didn't work. > >Is this a module you're creating? If so, can you post all (if it's brief) or >some of it so we can see what you're trying to do? > >I think what you probably want is: > >use vars qw( @EXPORT, @ISA ); >@EXPORT = qw( function_name ); >@ISA = qw( Exporter ); >require Exporter; > >I'm not sure what you mean by "argument". > >Regards, > >Troy > > __ Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/ Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[FWD: RE: Re: arguments with a module]
I meant to send this to the whole list. __ Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/ Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/ what I mean by argument is a switch/option that I pass to the module that I call whithin my main perl script. Yes I have those line in my module: >use vars qw( @EXPORT, @ISA ); >@EXPORT = qw( function_name ); >@ISA = qw( Exporter ); >require Exporter the module is so long that is not worth posting over here. All I need is to be able to pass an argument/switch to it, in my case is a file name. so I need to have something like use mymodule -myargument= I hope I am a little clearer this time. Thanks I.S Troy Denkinger <[EMAIL PROTECTED]> wrote: >On Thursday 16 August 2001 16:16, F.H wrote: >> Hi there, >> Can you use in a perl script a module with an argument. something like >> use mymodule -myargument; >> >> I get this message: "-myargument" is not exported bt the mymodule module. >> I tried in the module this >> @mymodule::EXPORT = qw(myargument ) >> and still it didn't work. > >Is this a module you're creating? If so, can you post all (if it's brief) or >some of it so we can see what you're trying to do? > >I think what you probably want is: > >use vars qw( @EXPORT, @ISA ); >@EXPORT = qw( function_name ); >@ISA = qw( Exporter ); >require Exporter; > >I'm not sure what you mean by "argument". > >Regards, > >Troy > > __ Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/ Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
formatting
Hi there, I hope this a is a simple one, I am trying to format a number so I get it rounded up to 4 decimals then padded with 2 zeros afterwards, $test = "142.09879543" ; $test = sprintf( "%.4f", $test); The output that I am looking for is 142.098800 This will be done via a loop through a whole set of numbers Thanks I.S __ Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/ Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Re: formatting
Sorry I meant round not round up and this did it: $test = sprintf( "%.4f00", $test); I.S Michael Fowler <[EMAIL PROTECTED]> wrote: >On Mon, Aug 20, 2001 at 12:30:07PM -0400, F.H wrote: >> I am trying to format a number so I get it rounded up to 4 decimals then >> padded with 2 zeros afterwards, >> $test = "142.09879543" ; >> $test = sprintf( "%.4f", $test); >> The output that I am looking for is >> 142.098800 >> This will be done via a loop through a whole set of numbers > >See perldoc -q 'round'. Given that you want to round a floating point value >in a specific direction (up) and then pad the number out a certain number of >zeroes, I don't know of a simple solution. You will likely need to write >your own function, perhaps some combination of splitting on the decimal and >using POSIX::ceil. > >Unless, of course, you didn't actually mean you want to round up, just that >you want to round, in which case you should take Bob Showalter's advice and >use sprintf or printf. > > >Michael >-- >Administrator www.shoebox.net >Programmer, System Administrator www.gallanttech.com >-- > __ Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/ Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
append line
Hi all, I have 2 files comma delimited that I want to merge based on similarity of first and last entry file1 looks like this alpha,1,2,3,K delta,3,4,5 file2 looks like this: beta,2,3,4 alpha,33,22,35,K the output I am looking for is: alpha,1,2,3,33,22,35 basically I want to append content of a line of file 1 if the first element and last element are same in both files is same . Thanks for your help I.S __ Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/ Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
exists
Hi, can someone give me an example on how to use 'if exists' to compare 2 hashes. Thanks I.S __ Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/ Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
hash access issue
Hi there, Here is my dilema: %HoH = ( flintstones => { lead1 => "fred", pal1 => "barney", }, jetsons => { lead2 => "george", wife2 => "jane", "his boy"3 => "elroy", }, simpsons=> { lead3 => "homer", wife3 => "marge", kid3 => "bart", }, ); $HoH{$key1}{$key2} is the basic structure of my hash. while I am reading from another file that provides 3 variables if $var1 eq flintsones and $var2 eq pal1, then: $HoH{$var1}{$var2} = "barney". Is ther a way that if $var1 eq "anything" and $var2 eq pal1 I can still get "barney". Any help is highly appreciated I.S __ Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/ Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Excel
Hi All, Anyone knows how to get a row/column count instead of specifying them as in foreach my $row (2..130) foreach my $column (2..130) Thanks I.S use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3;# die on errors... my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); my $Book = $Excel->Workbooks->Open("A:\\perl\\codes.xls"); my $Sheet = $Book->Worksheets(1); foreach my $row (2..130) { foreach my $col (1..3) { } my $test = $Sheet->Cells($row,3)->{'Value'}; print "$test\n"; } __ Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/ Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
dereferencing
Hi There, I am trying to get a count of elements of a reference to an array. $reftest = \@test $#reftest, doesn't seem to yield the number of arry elements. I appreciate if someone can help Thanks I.S -- __ Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/ Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]