Re: cgi calender
On 2/27/07, oryann9 <[EMAIL PROTECTED]> wrote: Problem: cgi calender daynames are not matching up with dates. For example: Todays date 02/27/2007 is being printed under Thursday instead of Tuesday. Is the problem that you need to determine the day of the week for a given date, or that you need to get something to line up vertically with something else? From looking briefly at your code, you seem to be using SQL to manipulate dates and times. In Perl, it's generally easier to use a module to do that. (Unless, of course, using SQL is part of the homework assignment.) --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: cgi calender
--- oryann9 <[EMAIL PROTECTED]> wrote: > All, > > I am having an issue getting my cgi calender to > print > correctly. Any help or hints would be appreciated! > I was thinking of manipulating the @weeks_anonymous > array with select dayofweek(curdate()) rather than > using hardcoed undef's > > Problem: cgi calender daynames are not matching up > with dates. For example: Todays date 02/27/2007 is > being printed under Thursday instead of Tuesday. > > Sun Mon Tues Wed Thurs Fri Sat > Feb 12, 07 Feb 13, 07 Feb 14, 07 Feb 15, 07 > Feb 16, 2007 Feb 17, 2007 Feb 18, 2007 Feb 19, 2007 > Feb 20, 2007 Feb 21, 2007 Feb 22, 2007 > Feb 23, 2007 Feb 24, 2007 Feb 25, 2007 Feb 26, 2007 > Feb 27, 2007 Feb 28, 2007 Mar 1, 2007 > Mar 2, 2007 Mar 3, 2007 Mar 4, 2007 Mar 5, 2007 Mar > 6, > 2007 Mar 7, 2007 Mar 8, 2007 > Mar 9, 2007 Mar 10, 2007 Mar 11, 2007 Mar 12, 2007 > Mar > 13, 2007 Mar 14, 2007 > > wherein today the 27th lines up with Thursday when > executing this code. I need it to correctly line up > with Tuesday. Finally, I am unable to use > HTML::Calander modules so this is not an option. > I added some code to address this issue, a hash and an array to store dayofweek numbers, but still trying to figure out how to merge these two code additions to solve the dates with dayname problem. #!/usr/bin/perl use strict; use warnings; require "dbi-lib.pl"; use CGI qw/:standard *table start_ul/, (-unique_headers); use CGI::Carp qw(fatalsToBrowser); use DBI; my $cgi = new CGI; local $sth; #--# # Function calls # #--# print_header(); initialize_dbi(); ## # Begin Main # ## print $cgi->header(), $cgi->start_html ('Lesson 11'), $cgi->h1 ({-style=>'Color:blue'},'SQL Class'); print "",$cgi->strong('Date/Time CGI Table:'),""; print $cgi->caption('MySQL calendar table output, Lesson 11:'); print ""; run_statement( "select date_format(curdate(), '%b %e, %Y');" ); my $today = $sth->fetchrow; run_statement("select dayofweek(curdate() );" ); my $dayofweek = $sth->fetchrow; #run_statement( "select date_format(curdate()-2,'%W');" ); #my $twodayago = $sth->fetchrow; #print "$twodayago "; my %WeekDays = ( Sunday=> 1, Monday=> 2, Tuesday => 3, Wednesday => 4, Thursday => 5, Friday=> 6, Saturday => 7 ); my ($day, $day1, $week,)= (0,0,0); my (@weeks, @weeks1, @weeks_anonymous,) = ((),(),()); ## Set up array with dates minus 15 days and plus 15 days from current date ## foreach $day ('-15' .. '15') { run_statement( "select date_format(date_add(curdate(), interval '$day' day), '%b %e, %Y');" ); push (@weeks, $sth->fetchrow); } ## Match up dates with dayofweek #'s ## foreach $day1 ('-15' .. '15') { run_statement( "select dayofweek(date_add(curdate(), interval '$day1' day));" ); push (@weeks1, $sth->fetchrow); } ## Begin Table ## print table({border=>undef}); #print Tr ({-align=>'CENTER',-valign=>'TOP'}); @weeks_anonymous = ( [$weeks[0], $weeks[1], $weeks[2], $weeks[3], $weeks[4], $weeks[5], $weeks[6] ], [$weeks[7], $weeks[8], $weeks[9], $weeks[10], $weeks[11], $weeks[12], $weeks[13] ], [$weeks[14], $weeks[15], $weeks[16], $weeks[17], $weeks[18], $weeks[19], $weeks[20] ], [$weeks[21], $weeks[22], $weeks[23], $weeks[24], $weeks[25], $weeks[26], $weeks[27] ], [$weeks[28], $weeks[29], $weeks[30], $weeks[31], undef, undef, undef ], ); foreach $element (@weeks_anonymous) { print Tr({-align=>'CENTER',-valign=>'TOP'}); for $date (@{$element}) { if (! defined $date) { print td (''); } elsif ($date eq $today) { print td(strong($date) ); } else { print td ($date); } } print $cgi->end_Tr; } print $cgi->end_html; Be a PS3 game guru. Get your game face on with the latest PS3 news and previews at Yahoo! Games. http://videogames.yahoo.com/platform?platform=120121 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
cgi calender
All, I am having an issue getting my cgi calender to print correctly. Any help or hints would be appreciated! I was thinking of manipulating the @weeks_anonymous array with select dayofweek(curdate()) rather than using hardcoed undef's Problem: cgi calender daynames are not matching up with dates. For example: Todays date 02/27/2007 is being printed under Thursday instead of Tuesday. Sun Mon Tues Wed Thurs Fri Sat Feb 12, 07 Feb 13, 07 Feb 14, 07 Feb 15, 07 Feb 16, 2007 Feb 17, 2007 Feb 18, 2007 Feb 19, 2007 Feb 20, 2007 Feb 21, 2007 Feb 22, 2007 Feb 23, 2007 Feb 24, 2007 Feb 25, 2007 Feb 26, 2007 Feb 27, 2007 Feb 28, 2007 Mar 1, 2007 Mar 2, 2007 Mar 3, 2007 Mar 4, 2007 Mar 5, 2007 Mar 6, 2007 Mar 7, 2007 Mar 8, 2007 Mar 9, 2007 Mar 10, 2007 Mar 11, 2007 Mar 12, 2007 Mar 13, 2007 Mar 14, 2007 wherein today the 27th lines up with Thursday when executing this code. I need it to correctly line up with Tuesday. Finally, I am unable to use HTML::Calander modules so this is not an option. #!/usr/bin/perl use strict; use warnings; require "dbi-lib.pl"; use CGI qw/:standard *table start_ul/, (-unique_headers); use CGI::Carp qw(fatalsToBrowser); use DBI; my $cgi = new CGI; local $sth; #--# # Function calls # #--# print_header(); initialize_dbi(); ## # Begin Main # ## print $cgi->header(), $cgi->start_html ('Oreilly SQL Class, Lesson 11'), # Header $cgi->h1 ({-style=>'Color:blue'},'Derek\'s SQL Class'); # Body print "",$cgi->strong('Date/Time CGI Table:'),""; print $cgi->caption('MySQL calendar table output, Lesson 11:'); print ""; run_statement( "select date_format(curdate(), '%b %e, %Y');" ); my $today = $sth->fetchrow; run_statement("select dayofweek(curdate() );" ); my $dayofweek = $sth->fetchrow; print $dayofweek; #&run_statement( "select date_format(curdate()-2,'%W');" ); #my $twodayago = $sth->fetchrow; #print "$twodayago "; my @WeekDays = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday); my ($day,$week,) = (0,0); my (@weeks, @weeks_anonymous,) = ((),()); foreach $day ('-15' .. '15') { run_statement( "select date_format(date_add(curdate(), interval '$day' day), '%b %e, %Y');" ); push (@weeks, $sth->fetchrow); } ## Begin Table ## print table({border=>undef}); print Tr ({-align=>'CENTER',-valign=>'TOP'}, td ([EMAIL PROTECTED])); @weeks_anonymous = ( [undef, undef, $weeks[0], $weeks[1], $weeks[2], $weeks[3] ], [$weeks[4], $weeks[5], $weeks[6], $weeks[7], $weeks[8], $weeks[9], $weeks[10] ], [$weeks[11], $weeks[12], $weeks[13], $weeks[14], $weeks[15], $weeks[16], $weeks[17] ], [$weeks[18], $weeks[19], $weeks[20], $weeks[21], $weeks[22], $weeks[23], $weeks[24] ], [$weeks[25], $weeks[26], $weeks[27], $weeks[28], $weeks[29], $weeks[30], $weeks[31] ], ); foreach $element (@weeks_anonymous) { print Tr({-align=>'CENTER',-valign=>'TOP'}); for $date (@{$element}) { if (! defined $date) { print td (''); } elsif ($date eq $today) { print td(strong($date)); } else { print td ($date); } } print $cgi->end_Tr; } print $cgi->end_html; The fish are biting. Get more visitors on your site using Yahoo! Search Marketing. http://searchmarketing.yahoo.com/arp/sponsoredsearch_v2.php -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: help with array within another array
Chas Owens wrote: > On 2/27/07, Neal Clark <[EMAIL PROTECTED]> wrote: > snip >> sorry about saying you had the wrong syntax earlier, i thought it >> was. i never knew you could do hashes with the comma operator. neat. >> i don't think its very clear syntactically but if it works it works :-) > snip > > In Perl 5 the only difference between the '=>' and ',' operators is > that the '=>' operator treats the word on the left like a string. The > '=>' is preferred when working with hashes because it provides a > visual cue that you are not dealing with a normal list. The key word there is "word". The => operator only works with "word" characters (a-z, A-Z, 0-9 and _). John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: help with array within another array
Neal Clark wrote: > you are working with two different variables. > > On Feb 27, 2007, at 12:24 PM, Ravi Malghan wrote: > >> what am I doing wrong here when trying to access the >> value john for node1 >> = >> $SESSION{FirstRun} = 1; > > this line creates a _hash_, %SESSION with one element (keyed by > FirstRun, value is 1). > >> %nodeowner = ("node1", "john", "node2", "nancy"); >> push(@SESSION, %nodeowner); > > here you're pushing to an array that perl has never heard of, @SESSION, > so perl goes ahead and makes an empty one for you before it pushes your > hash to it. you end up with an array of one element where $SESSION[0] = > %nodeowner Incorrect. %nodeowner = ("node1", "john", "node2", "nancy"); push(@SESSION, %nodeowner); Is equivalent to: push(@SESSION, ("node1", "john", "node2", "nancy")); Except that the order of the keys and values could be in any arbitrary order. (A hash in list context is just a list.) John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: help with array within another array
On 2/27/07, Neal Clark <[EMAIL PROTECTED]> wrote: snip sorry about saying you had the wrong syntax earlier, i thought it was. i never knew you could do hashes with the comma operator. neat. i don't think its very clear syntactically but if it works it works :-) snip In Perl 5 the only difference between the '=>' and ',' operators is that the '=>' operator treats the word on the left like a string. The '=>' is preferred when working with hashes because it provides a visual cue that you are not dealing with a normal list. In Perl 6 it will actually create a pair object, but since Perl 6 is a long way away still you don't really need to know that. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: help with array within another array
On 2/27/07, Ravi Malghan <[EMAIL PROTECTED]> wrote: what am I doing wrong here when trying to access the value john for node1 = $SESSION{FirstRun} = 1; %nodeowner = ("node1", "john", "node2", "nancy"); push(@SESSION, %nodeowner); print "node1: $SESSION{$nodeowner{node1}}\n"; snip Off that bat I would say there are several issues with this code: * you are using uppercase characters for variable names, convention says only bareword file handles should be all uppercase * you have an array and a hash named SESSION (which is confusing) * you don't appear to be using the strict module ("use strict" at the top of the code) * you are creating a useless intermediate variable (%nodeowner) * you are trying to get data out of the hash %SESSION that you put in the array @SESSION. Without more context I would rewrite your code like this: #!/usr/bin/perl use strict; my %session; $session{FirstRun} = 1; $session{node1} = 'john'; $session{node2} = 'nancy'; print "node1: $session{node1}\n"; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: help with array within another array
you are working with two different variables. On Feb 27, 2007, at 12:24 PM, Ravi Malghan wrote: what am I doing wrong here when trying to access the value john for node1 = $SESSION{FirstRun} = 1; this line creates a _hash_, %SESSION with one element (keyed by FirstRun, value is 1). %nodeowner = ("node1", "john", "node2", "nancy"); push(@SESSION, %nodeowner); here you're pushing to an array that perl has never heard of, @SESSION, so perl goes ahead and makes an empty one for you before it pushes your hash to it. you end up with an array of one element where $SESSION[0] = %nodeowner print "node1: $SESSION{$nodeowner{node1}}\n"; the value of $nodeowner{node1} is 'john', so here you are trying to access the %SESSION hash's key 'john', but it doesn't exist, the only key is 'FirstRun'. sorry about saying you had the wrong syntax earlier, i thought it was. i never knew you could do hashes with the comma operator. neat. i don't think its very clear syntactically but if it works it works :-) -neal == Thanks Ravi --- Neal Clark <[EMAIL PROTECTED]> wrote: ah. well in that case @SESSION = ( \%nodeowner, \%nodeseverity ); On Feb 27, 2007, at 11:59 AM, Ravi Malghan wrote: One correction: SESSION is just a single dimensional array @SESSION. Thanks Ravi --- Ravi Malghan <[EMAIL PROTECTED]> wrote: Hi: I just can't seem to figure this out. I am trying to declare two associative array (%nodeowner and %nodeseverity) within another array called %SESSION For example %nodeowner = ("node1", "john", "node2", "nancy"); %nodeseverity = ("node1", 5, "node2", 10); How do I declare %SESSION containing %nodeowner and %nodeseverity. And how do I access say the value John give node1 from the nodeowner array that is in SESSION? TIA Ravi __ __ Now that's room service! Choose from over 150,000 hotels in 45,000 destinations on Yahoo! Travel to find your fit. http://farechase.yahoo.com/promo-generic-14795097 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ __ __ TV dinner still cooling? Check out "Tonight's Picks" on Yahoo! TV. http://tv.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ __ __ Don't get soaked. Take a quick peak at the forecast with the Yahoo! Search weather shortcut. http://tools.search.yahoo.com/shortcuts/#loc_weather -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: help with array within another array
On 2/27/07, Ravi Malghan <[EMAIL PROTECTED]> wrote: Hi: I just can't seem to figure this out. I am trying to declare two associative array Just call them hashes, everybody else does. (%nodeowner and %nodeseverity) within another array called %SESSION For example %nodeowner = ("node1", "john", "node2", "nancy"); %nodeseverity = ("node1", 5, "node2", 10); It is much more clear to write this as my %nodeowner = ( node1 => "john", node2 => "nancy" ); my %nodeseverity = ( node1 => 5, node2 => 10 ); In Perl 5 the '=>' operator is just a fancy "," that treats the word on the left like a string. Also note the use of the 'my' keyword to make these variables lexical in scope. How do I declare %SESSION containing %nodeowner and %nodeseverity. And how do I access say the value John give node1 from the nodeowner array that is in SESSION? snip You can do it like by taking a reference (see perldoc perlref) of each hash: my %session = ( nodeseverity => \%nodeseverity, nodeowner => \%nodeowner ); But normally you wouldn't; you would just create %session (avoid all uppercase variable names, they look like file handles to most Perl programmers) in a nested manner: my %session = ( nodeowner => { node1 => "john", node2 => "nancy" }, nodeseverity { node1 => 5, node2 => 10 } ); You can then access the values like this print "$session{nodeower}{node1}\n"; You can nest hashes pretty much as far as you want. See the Hashes of Hashes section of perldoc perldsc for more deatailed information. In any case you should think very carefully about how you want to structure this data. Based on the names and type of data you shown it looks like an array of hashes would be better suited to your needs: my @session = ( { owner => 'john', severity => 5 }, { owner => 'nancy', severity => 10 } ); By doing it this way you can easily iterate over the nodes by saying for my $node (@session) { print "the owner of this session is $node->{owner} and its severity is $node->{severity}\n" } The issue is your use of parallel keys (node1, node2). Here is an example of the code above with your current data structure: for my $key (sort keys %{$session{nodeowner}}) { print "the owner of this session is $session{nodeowner}{$key} and its severity is $session{nodeseverity}{$key}\n"; } Not only is it uglier, it is buggy: what if there are more keys in nodeseverity than in nodeowner? A safer way (that still uses the hash of hashes structure instead of the array of hashes) would be to swap the order of the keys like this: my %session = ( node1 => { owner => 'john', severity => 5 }, node2 => { owner => 'nancy', severity => 10 } ); The code would then look like this: for my $key (sort keys %session) { print "the owner of this session ($key) is $session{$key}{owner} and its severity is $session{$key}{severity}\n"; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: help with array within another array
what am I doing wrong here when trying to access the value john for node1 = $SESSION{FirstRun} = 1; %nodeowner = ("node1", "john", "node2", "nancy"); push(@SESSION, %nodeowner); print "node1: $SESSION{$nodeowner{node1}}\n"; == Thanks Ravi --- Neal Clark <[EMAIL PROTECTED]> wrote: > ah. well in that case > > @SESSION = ( \%nodeowner, \%nodeseverity ); > > On Feb 27, 2007, at 11:59 AM, Ravi Malghan wrote: > > > One correction: SESSION is just a single > dimensional > > array @SESSION. > > > > Thanks > > Ravi > > --- Ravi Malghan <[EMAIL PROTECTED]> wrote: > > > >> Hi: I just can't seem to figure this out. > >> I am trying to declare two associative array > >> (%nodeowner and %nodeseverity) within another > array > >> called %SESSION > >> > >> For example > >> %nodeowner = ("node1", "john", "node2", "nancy"); > >> %nodeseverity = ("node1", 5, "node2", 10); > >> > >> How do I declare %SESSION containing %nodeowner > and > >> %nodeseverity. And how do I access say the value > >> John > >> give node1 from the nodeowner array that is in > >> SESSION? > >> > >> TIA > >> Ravi > >> > >> > >> > >> > > > __ > > > __ > >> Now that's room service! Choose from over > 150,000 > >> hotels > >> in 45,000 destinations on Yahoo! Travel to find > your > >> fit. > >> http://farechase.yahoo.com/promo-generic-14795097 > >> > >> -- > >> To unsubscribe, e-mail: > >> [EMAIL PROTECTED] > >> For additional commands, e-mail: > >> [EMAIL PROTECTED] > >> http://learn.perl.org/ > >> > >> > >> > > > > > > > > > > > __ > > > __ > > TV dinner still cooling? > > Check out "Tonight's Picks" on Yahoo! TV. > > http://tv.yahoo.com/ > > > > -- > > To unsubscribe, e-mail: > [EMAIL PROTECTED] > > For additional commands, e-mail: > [EMAIL PROTECTED] > > http://learn.perl.org/ > > > > > > Don't get soaked. Take a quick peak at the forecast with the Yahoo! Search weather shortcut. http://tools.search.yahoo.com/shortcuts/#loc_weather -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: help with array within another array
Ravi Malghan wrote: > Hi: I just can't seem to figure this out. > I am trying to declare two associative array > (%nodeowner and %nodeseverity) within another array > called %SESSION > > For example > %nodeowner = ("node1", "john", "node2", "nancy"); > %nodeseverity = ("node1", 5, "node2", 10); > > How do I declare %SESSION containing %nodeowner and > %nodeseverity. And how do I access say the value John > give node1 from the nodeowner array that is in > SESSION? $ perl -le' my %nodeowner= qw( node1 john node2 nancy ); my %nodeseverity = qw( node1 5node2 10 ); my %SESSION = reverse %nodeowner, %nodeseverity; print $SESSION{ john }; ' node1 John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Inefficient code?
Johnson, Reginald (GTI) wrote: > > From: John W. Krahn [mailto:[EMAIL PROTECTED] >> >> Johnson, Reginald (GTI) wrote: >>> >>> foreach $bkline (@bkupArray) { >>> my >>> ($bkup_node_ora,$bkup_db,$bk_blank,$id,$type,$cap,$start,$filler,$filler2,$filler3,$filler4,$bk_end,$rest)= >>> split (/,/,$bkline); >>> my ($bkup_node) = split(/_/,$bkup_node_ora); >>> >>> [ snip ] >> >> my @bkupArray; >> while ( ) { >> # Only need to store three fields from >> '/adsm/CRONJOBS/RMAN/lastbkup_temp' >> push @bkupArray, [ /^([^_]+)/, ( split /,/ )[ 1, 11 ] ]; >> } >> >> [ snip] > > Can you interpet to my how the regular expression in the code works. > push @bkupArray, [ /^([^_]+)/, ( split /,/ )[ 1, 11 ] ]; > > I understand the slice getting 1 and 11th element but don't get how the > regular expression works. The regular expression says to match starting at the beginning of the line one or more non-'_' characters and because of the list context the contents of the capturing parentheses are returned and become the first element of the anonymous array. John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: help with array within another array
ah. well in that case @SESSION = ( \%nodeowner, \%nodeseverity ); On Feb 27, 2007, at 11:59 AM, Ravi Malghan wrote: One correction: SESSION is just a single dimensional array @SESSION. Thanks Ravi --- Ravi Malghan <[EMAIL PROTECTED]> wrote: Hi: I just can't seem to figure this out. I am trying to declare two associative array (%nodeowner and %nodeseverity) within another array called %SESSION For example %nodeowner = ("node1", "john", "node2", "nancy"); %nodeseverity = ("node1", 5, "node2", 10); How do I declare %SESSION containing %nodeowner and %nodeseverity. And how do I access say the value John give node1 from the nodeowner array that is in SESSION? TIA Ravi __ __ Now that's room service! Choose from over 150,000 hotels in 45,000 destinations on Yahoo! Travel to find your fit. http://farechase.yahoo.com/promo-generic-14795097 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ __ __ TV dinner still cooling? Check out "Tonight's Picks" on Yahoo! TV. http://tv.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: help with array within another array
well first of all you're using the syntax for non-associative arrays (normal @arrays). your hash declarations should look like this: %nodeowner = (node1 => "john", node2 => "nancy"); %nodeseverity = (node1 => 5, node2 => 10); as for %SESSION, you could make a hash with reference to hash values: %SESSION = (owner => \%nodeowner, severity => \%nodeseverity); and access john like this: $SESSION{owner}->{node1}; (without understanding any more of what you're doing than you have written here) it seems like you might want to consider using the node identifier as the first key in %SESSION, and make the value a reference to hash keyed by the owner and severity: %SESSION = ( node1 => { owner => "john", severity => 5, }, node2 => { owner => "nancy", severity => 10, } } *shrug*. seems like a more natural way to refer to it to me. $SESSION{node1}->{owner} = john $SESSION{node1}->{severity} = 5, etc. take a look at perldoc perlreftut -Neal On Feb 27, 2007, at 11:53 AM, Ravi Malghan wrote: Hi: I just can't seem to figure this out. I am trying to declare two associative array (%nodeowner and %nodeseverity) within another array called %SESSION For example %nodeowner = ("node1", "john", "node2", "nancy"); %nodeseverity = ("node1", 5, "node2", 10); How do I declare %SESSION containing %nodeowner and %nodeseverity. And how do I access say the value John give node1 from the nodeowner array that is in SESSION? TIA Ravi __ __ Now that's room service! Choose from over 150,000 hotels in 45,000 destinations on Yahoo! Travel to find your fit. http://farechase.yahoo.com/promo-generic-14795097 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: help with array within another array
One correction: SESSION is just a single dimensional array @SESSION. Thanks Ravi --- Ravi Malghan <[EMAIL PROTECTED]> wrote: > Hi: I just can't seem to figure this out. > I am trying to declare two associative array > (%nodeowner and %nodeseverity) within another array > called %SESSION > > For example > %nodeowner = ("node1", "john", "node2", "nancy"); > %nodeseverity = ("node1", 5, "node2", 10); > > How do I declare %SESSION containing %nodeowner and > %nodeseverity. And how do I access say the value > John > give node1 from the nodeowner array that is in > SESSION? > > TIA > Ravi > > > > > Now that's room service! Choose from over 150,000 > hotels > in 45,000 destinations on Yahoo! Travel to find your > fit. > http://farechase.yahoo.com/promo-generic-14795097 > > -- > To unsubscribe, e-mail: > [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] > http://learn.perl.org/ > > > TV dinner still cooling? Check out "Tonight's Picks" on Yahoo! TV. http://tv.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: how good is 'crypt()'?
On 2/27/07, tom arnall <[EMAIL PROTECTED]> wrote: how good is 'crypt()'? it seems that for small differences in the target string you get duplicate digests. i get the following results (using debugger): snip Better than rot13, but worse than most other forms of encryption. The crypt function is not intended to withstand attacks where the target has access to the encrypted text. This is the reason most password programs will lock an account if more than three failures occur in a row. If you are looking for reasonably secure encryption you need to look at the Crypt::* modules on CPAN. Personally I just use GPG or PGP (depending on what is installed). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
help with array within another array
Hi: I just can't seem to figure this out. I am trying to declare two associative array (%nodeowner and %nodeseverity) within another array called %SESSION For example %nodeowner = ("node1", "john", "node2", "nancy"); %nodeseverity = ("node1", 5, "node2", 10); How do I declare %SESSION containing %nodeowner and %nodeseverity. And how do I access say the value John give node1 from the nodeowner array that is in SESSION? TIA Ravi Now that's room service! Choose from over 150,000 hotels in 45,000 destinations on Yahoo! Travel to find your fit. http://farechase.yahoo.com/promo-generic-14795097 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: how good is 'crypt()'?
On 2/27/07, tom arnall <[EMAIL PROTECTED]> wrote: how good is 'crypt()'? it seems that for small differences in the target string you get duplicate digests. That's not what it's "good" at. Are you trying to use it for checksumming or encryption, or something else it wasn't designed to do? i get the following results (using debugger): DB<1> $f='aaab' DB<2> $g='aaac' DB<3> p crypt($f,'ab') abBUNZY4cR2mg DB<4> p crypt($g,'ab') abBUNZY4cR2m Yes; those two "passwords" are effectively indistinguishable, as are infinitely many others. Many password systems impose a limit upon the meaningful length of passwords; the limit for crypt(2) is eight characters, I believe. If you wish to build a new system to do password verification, I'd recommend building it upon a modern (i.e. strong) cryptographic hash function, and allowing passphrases longer than eight characters. Cheers! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
how good is 'crypt()'?
how good is 'crypt()'? it seems that for small differences in the target string you get duplicate digests. i get the following results (using debugger): DB<1> $f='aaab' DB<2> $g='aaac' DB<3> p crypt($f,'ab') abBUNZY4cR2mg DB<4> p crypt($g,'ab') abBUNZY4cR2m tom arnall north spit, ca usa -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: Inefficient code?
-Original Message- From: John W. Krahn [mailto:[EMAIL PROTECTED] Sent: Sunday, February 18, 2007 4:15 PM To: Perl Beginners Subject: Re: Inefficient code? Johnson, Reginald (GTI) wrote: > My code is comparing the variables node and db in one input file to > bkup_node and bkup_db in the other input file. If they match then a > line is written to the output file. While I am getting the desired > output I don't think I am doing this in the most efficient manor. When I > have the print statement turned on I see that the code is still > comparing the same node and db after a match is found. Any advice would > be appreciated. You don't need to store both files in memory and you don't even need the whole lines of the file you do store in memory. You could do something like this: #!/usr/bin/perl use strict; use warnings; open RMANFILE, '<', "/adsm/CRONJOBS/RMAN/rman_out_temp-$today" or die "cannot open rman file: $!\n"; open LASTBKUPFILE, '<', '/adsm/CRONJOBS/RMAN/lastbkup_temp' or die "cannot open last backup file: $!\n"; open OUTFILE, '>', "/adsm/CRONJOBS/RMAN/RMANFILES/rman_out_temp-$today" or die "cannot open out file: $!\n"; my @bkupArray; while ( ) { # Only need to store three fields from '/adsm/CRONJOBS/RMAN/lastbkup_temp' push @bkupArray, [ /^([^_]+)/, ( split /,/ )[ 1, 11 ] ]; } while ( my $line = ) { chomp $line; my ( $node, $db ) = split ' ', $line; for my $bkline ( @bkupArray ) { print "node=>$node<= bkup_node=>$bkline->[0]<=db=>$db<= bkup_db=>$bkline->[1]<=\n"; if ( index( $node, $bkline->[0] ) >= 0 && index( $db, $bkline->[1] ) >= 0 ) { print OUTFILE "$line $bkline->[2]\n"; } } } __END__ Can you interpet to my how the regular expression in the code works. push @bkupArray, [ /^([^_]+)/, ( split /,/ )[ 1, 11 ] ]; I understand the slice getting 1 and 11th element but don't get how the regular expression works. If you are not an intended recipient of this e-mail, please notify the sender, delete it and do not read, act upon, print, disclose, copy, retain or redistribute it. Click here for important additional terms relating to this e-mail. http://www.ml.com/email_terms/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: slurp hash from file
On Tue, 27 Feb 2007, Adriano Ferreira wrote: On 2/27/07, Jorge Almeida <[EMAIL PROTECTED]> wrote: Let's say your data is in the file "data.pl". Then my %hash = do "data.pl"; my $hash_ref = \%hash; Great! Thanks. -- Jorge Almeida -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: slurp hash from file
On 2/27/07, Jorge Almeida <[EMAIL PROTECTED]> wrote: I want to define a hash reference like this: my $h={ a => 'a', b => 'aa &&\ bbb', }; (Note the string containing escaped newlines.) Now, the point is that I have the block a => 'a', b => 'aa &&\ bbb', in a text file. It would be nice to be able to just slurp the file as-is to define $h. Is there any way to do this? The best workaround I can think of is to have a modified file, with entries separated by empty lines: a => 'a', b => 'aa &&\ bbb', I could then slurp the file as a single string, split the string on /\n\n/, etc., because I know the hash values will not contain empty lines. But this leaves an uncomfortable feeling, since the original file contents are already as we would write them in the main program... Any idea? Let's say your data is in the file "data.pl". Then my %hash = do "data.pl"; my $hash_ref = \%hash; -- Jorge Almeida -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
slurp hash from file
I want to define a hash reference like this: my $h={ a => 'a', b => 'aa &&\ bbb', }; (Note the string containing escaped newlines.) Now, the point is that I have the block a => 'a', b => 'aa &&\ bbb', in a text file. It would be nice to be able to just slurp the file as-is to define $h. Is there any way to do this? The best workaround I can think of is to have a modified file, with entries separated by empty lines: a => 'a', b => 'aa &&\ bbb', I could then slurp the file as a single string, split the string on /\n\n/, etc., because I know the hash values will not contain empty lines. But this leaves an uncomfortable feeling, since the original file contents are already as we would write them in the main program... Any idea? -- Jorge Almeida -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/