Re: creating blackjack perl program (starts with pseudocode first)
Rob Dixon wrote: I suggest you start by describing a very simple game that's not blackjack. One player gets dealt cards until he hits 21 or more. 21 is a win, more is a loss. Then add a dealer's hand. Then add face down cards Then add betting Then add, erm, insurance? Finish with the green baize ;) HTH, Rob Hey, thanks for the quick feedback. I worked on from 1-6 and will work on 7 tomorrow. See if this is any better ### 52 cards in deck consist of 2-10 and J, Q, K(which all 3 of them has value of 10) and A (which has either value of 1 or 11 ) and there are 3 suits (diamond,clover,heart, requirements: 7 decks ( 52 X 7 = 364 ) # not sure 6 or 7 decks but let's just say 7 for now Player will have $500 and we will call that bank. Each bet's minimum is $25 and maximum is $500 1. Take 7 decks of cards one big pile and shuffle them 2. Have player cut the deck(must be in 2nd half of deck but cannot be last 20% of the deck; somewhere between past 50% and before 80%) and put a marker on it # so it knows where to stop ### The reason, cutting the deck after cards are shuffled is to make sure players do not know when the deck ends ### Meaning, if someone was counting cards(sort of trying to memorize what cards already came out, they can sort of guess ### as decks are running out. If you cut the deck, it's harder to guestimate, although counting cards can still give player bit of advantage; it's still gambling and probability --- game starts--- 3. Player places the bet which must be greater or equal to minimum and less or equal to max and also his bank must have that amount in order to bet ( bank - bet ) 4.dealer deals a card ### player and dealer each gets 2 cards. 2nd card that dealer gets is face down so nobody knows the value of the card first dealer will deal a face up card to player which we will call player_total second, dealer will deal a face up card for dealer himself which we will call dealer_total third, dealer will deal a face up card to player which we will call player_next fourth dealer will deal a face down card for dealer himself which we will call dealer_next 5.If player has blackjack( 10 + A ), add 1.5 x bet + bet to his bank and bet again(go back to step 3) 6.If dealer has A in face up card, offer insurance if answer is yes then player must bet additional 50% of his current bet ( bet x .5 ) which we will call insurance_money (bet x .5) = insurance_money bank - insurance_money### current total bank after putting insurance if answer is no insurance_money is 0 now check the face down card ( dealer_next ) if dealer_next is 10 and insurance_money is 0 player lose the bet and game over and go back to step 3 and bet again if dealer_next is not 10 and insurnace_money is 0 game continues, go to step 7 if dealer_next is 10 and insurance_money is greater than 0 add back player's bet and insurance money to his bank ( bank + bet + insurance_money) game starts over and go back to step 3 and bet again if dealer_next is NOT 10 and insurance_money is greater than 0 (bank - insurance_money - bet )and game continues, go to step 7 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: creating blackjack perl program (starts with pseudocode first)
Richard Lee wrote: Rob Dixon wrote: I suggest you start by describing a very simple game that's not blackjack. One player gets dealt cards until he hits 21 or more. 21 is a win, more is a loss. Then add a dealer's hand. Then add face down cards Then add betting Then add, erm, insurance? Finish with the green baize ;) HTH, Rob Hey, thanks for the quick feedback. I worked on from 1-6 and will work on 7 tomorrow. See if this is any better ### 52 cards in deck consist of 2-10 and J, Q, K(which all 3 of them has value of 10) and A (which has either value of 1 or 11 ) and there are 3 suits (diamond,clover,heart, requirements: 7 decks ( 52 X 7 = 364 ) # not sure 6 or 7 decks but let's just say 7 for now Player will have $500 and we will call that bank. Each bet's minimum is $25 and maximum is $500 1. Take 7 decks of cards one big pile and shuffle them 2. Have player cut the deck(must be in 2nd half of deck but cannot be last 20% of the deck; somewhere between past 50% and before 80%) and put a marker on it # so it knows where to stop ### The reason, cutting the deck after cards are shuffled is to make sure players do not know when the deck ends ### Meaning, if someone was counting cards(sort of trying to memorize what cards already came out, they can sort of guess ### as decks are running out. If you cut the deck, it's harder to guestimate, although counting cards can still give player bit of advantage; it's still gambling and probability --- game starts--- 3. Player places the bet which must be greater or equal to minimum and less or equal to max and also his bank must have that amount in order to bet ( bank - bet ) 4.dealer deals a card ### player and dealer each gets 2 cards. 2nd card that dealer gets is face down so nobody knows the value of the card first dealer will deal a face up card to player which we will call player_total second, dealer will deal a face up card for dealer himself which we will call dealer_total third, dealer will deal a face up card to player which we will call player_next fourth dealer will deal a face down card for dealer himself which we will call dealer_next 5.If player has blackjack( 10 + A ), add 1.5 x bet + bet to his bank and bet again(go back to step 3) 6.If dealer has A in face up card, offer insurance if answer is yes then player must bet additional 50% of his current bet ( bet x .5 ) which we will call insurance_money (bet x .5) = insurance_money bank - insurance_money### current total bank after putting insurance if answer is no insurance_money is 0 now check the face down card ( dealer_next ) if dealer_next is 10 and insurance_money is 0 player lose the bet and game over and go back to step 3 and bet again if dealer_next is not 10 and insurnace_money is 0 game continues, go to step 7 if dealer_next is 10 and insurance_money is greater than 0 add back player's bet and insurance money to his bank ( bank + bet + insurance_money) game starts over and go back to step 3 and bet again if dealer_next is NOT 10 and insurance_money is greater than 0 player loses the insurance_money but game continues , go to step 7-- this was corrected one correction above -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: creating blackjack perl program (starts with pseudocode first)
Richard Lee wrote: Rob Dixon wrote: I suggest you start by describing a very simple game that's not blackjack. One player gets dealt cards until he hits 21 or more. 21 is a win, more is a loss. Then add a dealer's hand. Then add face down cards Then add betting Then add, erm, insurance? Finish with the green baize ;) HTH, Rob Hey, thanks for the quick feedback. I worked on from 1-6 and will work on 7 tomorrow. See if this is any better ### 52 cards in deck consist of 2-10 and J, Q, K(which all 3 of them has value of 10) and A (which has either value of 1 or 11 ) and there are 3 suits (diamond,clover,heart, requirements: 7 decks ( 52 X 7 = 364 ) # not sure 6 or 7 decks but let's just say 7 for now Player will have $500 and we will call that bank. Each bet's minimum is $25 and maximum is $500 1. Take 7 decks of cards one big pile and shuffle them 2. Have player cut the deck(must be in 2nd half of deck but cannot be last 20% of the deck; somewhere between past 50% and before 80%) and put a marker on it # so it knows where to stop ### The reason, cutting the deck after cards are shuffled is to make sure players do not know when the deck ends ### Meaning, if someone was counting cards(sort of trying to memorize what cards already came out, they can sort of guess ### as decks are running out. If you cut the deck, it's harder to guestimate, although counting cards can still give player bit of advantage; it's still gambling and probability --- game starts--- 3. Player places the bet which must be greater or equal to minimum and less or equal to max and also his bank must have that amount in order to bet ( bank - bet ) 4.dealer deals a card ### player and dealer each gets 2 cards. 2nd card that dealer gets is face down so nobody knows the value of the card first dealer will deal a face up card to player which we will call player_total second, dealer will deal a face up card for dealer himself which we will call dealer_total third, dealer will deal a face up card to player which we will call player_next fourth dealer will deal a face down card for dealer himself which we will call dealer_next 5.If player has blackjack( 10 + A ), add 1.5 x bet + bet to his bank and bet again(go back to step 3) 6.If dealer has A in face up card, offer insurance if answer is yes then player must bet additional 50% of his current bet ( bet x .5 ) which we will call insurance_money (bet x .5) = insurance_money bank - insurance_money### current total bank after putting insurance if answer is no insurance_money is 0 now check the face down card ( dealer_next ) if dealer_next is 10 and insurance_money is 0 player lose the bet and game over and go back to step 3 and bet again if dealer_next is not 10 and insurnace_money is 0 game continues, go to step 7 if dealer_next is 10 and insurance_money is greater than 0 add back player's bet and insurance money to his bank ( bank + bet + insurance_money) game starts over and go back to step 3 and bet again if dealer_next is NOT 10 and insurance_money is greater than 0 (bank - insurance_money - bet )and game continues, go to step 7 You seem to have disregarded all that I posted before. I wish you well, but I think your design is way too detailed too early. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Converting integer + mantissa to float
Jay Savage schreef: two integers as input that represent a single float. The first is the integer part, the second is hat mantissa. How do I recomine them into a single float? my $float = $int_part . '.' . $matissa; #or my $float = sprintf %u.%u, $int_part, $mantissa; The sprintf() makes me think that you receive the numbers, or at least the mantissa, with possible leading zeroes. I would add the venus operator: my $float = 0+ sprintf(%u.%u, $int_part, $mantissa); The $int_part is always non-negative? -- Affijn, Ruud Gewoon is een tijger. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
csv to jpg
Hi, I am having some prstat log files. From which i want to make some graphs. Any pointers are greatly appreciated. -- Thanks Regards, Santosh Reddy.
Re: installing Lingua-EN-Sentence-0.25 error - wrong version
[EMAIL PROTECTED] schreef: I downloaded Lingua-EN-Sentence-0.25 from CPan (http://search.cpan.org/ ~shlomoy/Lingua-EN-Sentence-0.25/). I followed the install instructions and everything seemed to go fine. However when I attempt to use it in my perl script I get the error Lingua::EN::Sentence version 1 required--this is only version 0.25 at / usr/share/perl/5.8/Exporter/Heavy.pm line 107. I haven't even used a line of its code just added use Lingua::EN::Sentence. Does anyone know what this error message actually means./A way to remedy the situation. You didn't copy/paste code showing your problem, so I must assume that you forgot to put a ; at the end of your added line. For example: #!/usr/bin/perl use strict; use warnings; use Lingua::EN::Sentence 1; -- Affijn, Ruud Gewoon is een tijger. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Meaning of [EMAIL PROTECTED]
Hi there, I am stuck with something here. What does the following piece of code mean? my @temp1; my @temp2; $cnt=0; $temp2[$cnt] = [EMAIL PROTECTED]; What is the kind of data stored in $tempFieldNames[$information] ? Please help. Sundeep -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: csv to jpg
On Thu, Jun 12, 2008 at 4:49 AM, Santosh Reddy [EMAIL PROTECTED] wrote: Hi, I am having some prstat log files. From which i want to make some graphs. Any pointers are greatly appreciated. Checkout rrd (Round Robin Database) they're also bindings available for perl. -- Thanks Regards, Santosh Reddy. -- [ Rodrick R. Brown ] http://www.rodrickbrown.com http://www.linkedin.com/in/rodrickbrown
Re: Meaning of [EMAIL PROTECTED]
On Thu, Jun 12, 2008 at 5:28 AM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi there, I am stuck with something here. What does the following piece of code mean? my @temp1; my @temp2; $cnt=0; $temp2[$cnt] = [EMAIL PROTECTED]; What is the kind of data stored in $tempFieldNames[$information] ? Your creating a reference to an array as and storing that reference in array index 0. Data::Dumper can be very helpful for understanding what's going on here its no different than doing saying $temp2[$cnt] = [EMAIL PROTECTED]; #!/usr/bin/perl -w use strict; use Data::Dumper; my @temp1 = (Apple, Orange, Mango); my @temp2; my $cnt=0; $temp2[$cnt] = [EMAIL PROTECTED]; print Dumper([EMAIL PROTECTED]); $VAR1 = [ [ 'Apple', 'Orange', 'Mango' ] ]; As you can see here the first element index 0 in your array contains an anonymous array. I hope this is clear. Please help. Sundeep -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- [ Rodrick R. Brown ] http://www.rodrickbrown.com http://www.linkedin.com/in/rodrickbrown
Re: Meaning of [EMAIL PROTECTED]
On Thu, Jun 12, 2008 at 5:28 PM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi there, I am stuck with something here. What does the following piece of code mean? my @temp1; my @temp2; $cnt=0; $temp2[$cnt] = [EMAIL PROTECTED]; What is the kind of data stored in $tempFieldNames[$information] ? Hi, [EMAIL PROTECTED] means creating an anonymous array. This anonymous's elements are the ones of @temp1. An anonymous array is a scalar, this scalar is assigned to $temp2[$cnt]. -- Jeff Peng - [EMAIL PROTECTED] Professional Squid supports in China http://www.ChinaSquid.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: csv to jpg
On Thu, Jun 12, 2008 at 4:49 PM, Santosh Reddy [EMAIL PROTECTED] wrote: Hi, I am having some prstat log files. From which i want to make some graphs. Any pointers are greatly appreciated. Hi, Parse the logs and write the results to a database, then using GD::Graph or something like that to make graphs in web pages. -- Jeff Peng - [EMAIL PROTECTED] Professional Squid supports in China http://www.ChinaSquid.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Starting perl script @ boot up
Hi all, I'm trying to start one perl script at system boot up time. I'm using HP UX 11 and I did standard procedure to start process at start up (http://strc.comet.ucar.edu/unix/textfiles/startboot.htm standard process). Here I'm able to run this perl script through command prompt but system is not able to start same processes while botting up. Do any one have pointers? If this question is not relevant to this mailing list, Please direct me to proper mailing list. Rajnikant Jachak | Software Engg | Persistent Systems Limited mailto:[EMAIL PROTECTED] [EMAIL PROTECTED] | Cell: +91 9822204088 | Tel: +91 (20) 3023 2479 Persistent Systems - Innovations in software product design,development and delivery - http://www.persistentsys.com/ www.persistentsys.com DISCLAIMER == This e-mail may contain privileged and confidential information which is the property of Persistent Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Ltd. does not accept any liability for virus infected mails.
Re: Starting perl script @ boot up
On Thu, Jun 12, 2008 at 7:11 PM, Rajnikant [EMAIL PROTECTED] wrote: Hi all, I'm trying to start one perl script at system boot up time. I'm using HP UX 11 and I did standard procedure to start process at start up (http://strc.comet.ucar.edu/unix/textfiles/startboot.htm standard process). Here I'm able to run this perl script through command prompt but system is not able to start same processes while botting up. This is most likely a system issue, not the Perl problems. But there are some hp-unix hackers here, maybe they can help you. -- Jeff Peng - [EMAIL PROTECTED] Professional Squid supports in China http://www.ChinaSquid.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Using wget within perl
I want to wget several image files from a server at a time with the same format. So, I am trying to write a perl script which calls wget continuously, but with diffferent values of the variables. However, when I use a system( $foo)call, with $foo as the string with variables, it doesn't seem to work, while if the wget command is used at the terminal, it works just fine... Could anyone throw some light on this matter?...The code is given below for reference... #!/usr/bin/perl $single = http://casjobs.sdss.org/ImgCutoutDR6/getjpeg.aspx? ra=18.87667dec=-0.86083scale=0.39612width=400height=400opt=GSTquery=SR(10,20); system( wget $single ) After running this, I get the following error sh: -c: line 0: syntax error near unexpected token `(' sh: -c: line 0: `wget http://casjobs.sdss.org/ImgCutoutDR6/getjpeg.aspx?ra=18.87667dec=-0.86083scale=0.39612width=400height=400opt=GSTquery=SR(10,20) ' -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Using wget within perl
On Thu, Jun 12, 2008 at 1:31 PM, stallomir [EMAIL PROTECTED] wrote: I want to wget several image files from a server at a time with the same format. So, I am trying to write a perl script which calls wget continuously, but with diffferent values of the variables. However, when I use a system( $foo)call, with $foo as the string with variables, it doesn't seem to work, while if the wget command is used at the terminal, it works just fine... Could anyone throw some light on this matter?...The code is given below for reference... Seems it's due to the meta characters in the quoted url. try add a statement: $url = quotemeta($url); before the wget system call. Btw, why not using the pure perl way of getting a file? LWP::Simple is really easy to do it. -- Jeff Peng - [EMAIL PROTECTED] Professional Squid supports in China http://www.ChinaSquid.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: csv to jpg
Do we need to have a database for this? Cant we do it without a database. Just using txt or csv file and make a jpg or png out of it On Thu, Jun 12, 2008 at 4:34 PM, Jeff Peng [EMAIL PROTECTED] wrote: On Thu, Jun 12, 2008 at 4:49 PM, Santosh Reddy [EMAIL PROTECTED] wrote: Hi, I am having some prstat log files. From which i want to make some graphs. Any pointers are greatly appreciated. Hi, Parse the logs and write the results to a database, then using GD::Graph or something like that to make graphs in web pages. -- Jeff Peng - [EMAIL PROTECTED] Professional Squid supports in China http://www.ChinaSquid.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- Thanks Regards, Santosh Reddy.
Re: csv to jpg
On Thu, Jun 12, 2008 at 8:12 PM, Santosh Reddy [EMAIL PROTECTED] wrote: Do we need to have a database for this? Cant we do it without a database. Just using txt or csv file and make a jpg or png out of it Sure you can. But using a database have any bad points? -- Jeff Peng - [EMAIL PROTECTED] Professional Squid supports in China http://www.ChinaSquid.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: csv to jpg
Why should we have a database for simple operation like this. I am assuming that you are referring to RDBMS. On Thu, Jun 12, 2008 at 5:45 PM, Jeff Peng [EMAIL PROTECTED] wrote: On Thu, Jun 12, 2008 at 8:12 PM, Santosh Reddy [EMAIL PROTECTED] wrote: Do we need to have a database for this? Cant we do it without a database. Just using txt or csv file and make a jpg or png out of it Sure you can. But using a database have any bad points? -- Jeff Peng - [EMAIL PROTECTED] Professional Squid supports in China http://www.ChinaSquid.com/ -- Thanks Regards, Santosh Reddy.
How to get scalar context of a list within a complex array
I have a complex array containing references to hashes. Some of the hash keys point to anonymous lists. A typical element from this array looks like this: { '_is_control_field' = '', '_ind2' = '0', '_subfields' = [ 'a', 'Japanese paper folding' ], '_warnings' = [], '_tag' = 450, '_ind1' = ' ' }; Since this is the first array element, to access the second item in the list that _subfields points to, I use this syntax: $fields[0] {'_subfields'}-[1]; This returns 'Japanese paper folding.' This list can vary in size from element to element, so I would like a way to refer to the list in scalar context to get its size. How do I do that? (My current approach is to simply iterate through the list, pushing the elements onto another array until I reach undefined.) Many thanks! - Chris Morgan
Re: How to get scalar context of a list within a complex array
On Thu, Jun 12, 2008 at 9:37 PM, Christopher Morgan [EMAIL PROTECTED] wrote: This list can vary in size from element to element, so I would like a way to refer to the list in scalar context to get its size. How do I do that? Hi, since $fields[0]-{'_subfields'} is an anonymous array, you can derefer it by saying, @{ $fields[0]-{'_subfields'} }; So, scalar @{ $fields[0]-{'_subfields'} }; will get its length. -- Jeff Peng - [EMAIL PROTECTED] Professional Squid supports in China http://www.ChinaSquid.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
pointers in per
Dear gurus nbsp; I have to write a program with configuration file *.CFG, inbsp;came to knownbsp;have to use pointers nbsp; I amnbsp;new to pointer in perl cannbsp;i get some tipsnbsp;about pointers in perl, where can i getnbsp;study materials and sample files. Anticipating a favorable reply nbsp; Regards nbsp; Manikandan Nnbsp; nbsp; nbsp; __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Re: pointers in per
On Thu, Jun 12, 2008 at 10:22 PM, mani kandan [EMAIL PROTECTED] wrote: Dear gurus I have to write a program with configuration file *.CFG, i came to know have to use pointers I am new to pointer in perl can i get some tips about pointers in perl, where can i get study materials and sample files. Hello, Perl doesn't have so features called pointers as C's. Perl uses reference. see `perldoc perlref` for details, or this page: http://perldoc.perl.org/perlref.html -- Jeff Peng - [EMAIL PROTECTED] Professional Squid supports in China http://www.ChinaSquid.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: How to get scalar context of a list within a complex array
Great! That did it -- thanks, Jeff! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Meaning of [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote: Hi there, Hello, I am stuck with something here. What does the following piece of code mean? my @temp1; Create the lexical array @temp1 and initialise it with nothing (empty.) my @temp2; Create the lexical array @temp2 and initialise it with nothing (empty.) $cnt=0; Assign the value 0 to the scalar variable $cnt. $temp2[$cnt] = [EMAIL PROTECTED]; Copy the contents of the array @temp1 to an anonymous array and assign the reference of that anonymous array to the scalar variable $temp2[$cnt]. What is the kind of data stored in $tempFieldNames[$information] ? A scalar value of some kind. 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: Meaning of [EMAIL PROTECTED]
On Jun 12, 6:41 am, [EMAIL PROTECTED] (Rodrick Brown) wrote: On Thu, Jun 12, 2008 at 5:28 AM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi there, I am stuck with something here. What does the following piece of code mean? my @temp1; my @temp2; $cnt=0; $temp2[$cnt] = [EMAIL PROTECTED]; What is the kind of data stored in $tempFieldNames[$information] ? Your creating a reference to an array as and storing that reference in array index 0. Data::Dumper can be very helpful for understanding what's going on here its no different than doing saying $temp2[$cnt] = [EMAIL PROTECTED]; Actually, it's quite different. In the OP, $temp2[$cnt] is a reference to an anonymous array that happens to have been initialized with the data that was in @temp1 at the time it was created. In your modification, $temp2[$cnt] is a reference to @temp1. In the OP, if any following statements modify @temp1, those changes will not be reflected in @{$temp2[$cnt]}. Similarly, changes to @{$temp2[$cnt]} will not be reflected in @temp1. In your modification, changes to one will affect the other, because they're the same array. Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Program to fetch user information
Hi Rob, I have interpolated the server and the user name as in this: /Win32::NetAdmin::UserGetAttributes(servername,myself,my $password,my $passwordAge,my $privilege,my $homeDir,my $comment,my $flags,my $scriptPath); / The only thing it shows is this: /The homedir for the user is/ I tried with the IP as well, still no luck. What else can be done. Thanks. Rob Dixon wrote: Gunwant Singh wrote: I have written a small Perl script so to fetch information about the user. Here is the code: /1use strict; 2use warnings; 3use Win32::Netadmin; 4Win32::NetAdmin::UserGetAttributes(my $server,my $userName,my $password,my $passwordAge,my $privilege,my $homeDir,my $comment,my $flags,my $scriptPath); 5print The homedir for the user is $homeDir\n;/ When I tried to run it, I got this: /Use of uninitialized value in subroutine entry at C:\Documents and Settings\Myself\Desktop\code\mac-info.pl line 4. Use of uninitialized value in subroutine entry at C:\Documents and Settings\Myself\Desktop\code\mac-info.pl line 4. Use of uninitialized value in concatenation (.) or string at C:\Documents and Settings\Myself\Desktop\code\mac-info.pl line 5. The homedir for the user is/ I am not sure, what is the problem. Can anyone help me on this? You need to specify the server and user name. Win32::NetAdmin::UserGetAttributes('', 'Rob', $password, $passwordAge, $privilege, $homeDir, $comment, $flags, $scriptPath); HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Error while compiling GD
Hi, I am using Solaris 10 and i am trying to compile GD. i am getting the following error. please help me how to resolve this. bash-3.00$ make gcc -c -I/usr/include -I/usr/include/gd -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -xarch=v8 -D_TS_ERRNO -xO3 -xspace -xildoff -DVERSION=\2.39\ -DXS_VERSION=\2.39\ -KPIC -I/usr/perl5/5.8.4/lib/sun4-solaris-64int/CORE -DHAVE_FT -DHAVE_XPM -DHAVE_GIF -DHAVE_PNG -DHAVE_ANIMGIF GD.c gcc: unrecognized option `-KPIC' gcc: language ildoff not recognized gcc: GD.c: linker input file unused because linking not done rm -f blib/arch/auto/GD/GD.so LD_RUN_PATH=/usr/lib cc -G GD.o -o blib/arch/auto/GD/GD.so -L/usr/lib/X11 -L/usr/X11/lib -L/usr/lib -lpng -lz -lm -lX11 -lXpm /usr/ucb/cc: language optional software package not installed *** Error code 1 make: Fatal error: Command failed for target `blib/arch/auto/GD/GD.so' -- Thanks Regards, Santosh Reddy.
unpack long long ( 8 bytes)
Hi all , How do i unpack long long type which it has 8 bytes . I tried unpack (l8,$val) but I always get 0 or just spaces When i try unpack(l4,substr($val,4)) - i'm getting the rcorrect value but for a little numbers . Please help me , it makes me crazy Golan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: looping 2 times through 5000 differs from 5000 times through 2
From: Rob Dixon [EMAIL PROTECTED] oldgeezer wrote: foreach my $entry (uniq @IK){ foreach my $line(@DATA) { # Note /;$entry;/ takes longer than # /$entry;/ and that takes longer than /$entry/ # But /$entry/ also splits remarks_entries. # So I need the trailing ';' because they # are not in the remarks_entries # Appending the i, like: /$entry/i slows # down too. I don't need it. # Prepending m, like m/$entry/ # does not change anything (timewise). # For the average person /$entry;/ is fastest if($line=~ /$entry;/) { splitline($line); [EMAIL PROTECTED] changes when I splitline #next; don't do this. It makes it slower }; }; }; Your comments are fine, but they have obscured your code structure. How about # Note /;$entry;/ takes longer than /$entry;/ and that takes # longer than /$entry/ But /$entry/ also splits # remarks_entries. So I need the trailing ';' because they # are not in the remarks_entries. # # Appending the i, like: /$entry/i slows down too. I don't # need it. Prepending m, like m/$entry/ does not change # anything (timewise). For the average person /$entry;/ is # fastest # foreach my $entry (uniq @IK) { foreach my $line (@DATA) { if ($line=~ /$entry;/) { splitline($line); # @IK changes when I splitline #next; don't do this. It makes it slower } } } But even then I have issues with what your comments say. First of all you are obsessed with speed over function. A programmer's primary duty is to make things that work, and look like they work; it is only a secondary consideration to make things faster if they turn out to be too slow. Agreed. OTOH, in this case one might actually make it even quicker using qr//: foreach my $entry (uniq @IK) { my $entry_re = qr/$entry;/; foreach my $line (@DATA) { if ($line=~ $entry_re) { splitline($line); # @IK changes when I splitline #next; don't do this. It makes it slower } } } Another thing ... if splitline($line) indeed does change @IK (which is a bad thing, it should not modify something behind the scenes) do you expect the outer foreach to note that? I hope not, in any case, it doesn't. Especially if the $entry is long and is actually a regexp and not a string of letters. Of course if it's not meant to be a regexp you should use my $entry_re = qr/\Q$entry\E;/; Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: hash keys
On Jun 12, 12:15 am, [EMAIL PROTECTED] (Beast) wrote: Why this following code has not working as expected? print Number of element(s) : . sprintf(%10d, keys(%hash) ) . \n; The keys() function does two different things, depending on context. In scalar context, it returns the number of key/value pairs in the hash. In list context, it returns a list of the keys. You probably knew that, but didn't realize that you're using it in a list context here. The arguments to a function are a list, and so Perl is expecting a list of values to be passed to sprintf(). Anywhere Perl expects a list, if it sees a function/subroutine, it calls that function/subroutine in list context. Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Complex Regular Expression Matching
Hello, I have a regular expression that is used to take data from a table. while($innerTable =~ m/\TR\ \TD\ \A HREF=.*? target=dictionary TITLE=.*?\ (.*?)\\/A\ \\/TD\ \TD\ (.*?) \\/TD\ \TD\ (.*?) \\/TD\ \TD\(\s*\A TITLE=.*? HREF=.*? TARGET=dictionary\ (.*?)\\/A\=[0-9]+\s*(\\/A\)*\s*)*\\/TD\/gs) { print $1 $2 $3 $5\n; } This matches the pattern fine and is printing almost the correct results. The only thing missing is the last section, where I have a variable group inside a repeated match: (\s*\A TITLE=.*? HREF=.*? TARGET=dictionary\ (.*?)\\/A \=[0-9]+\s*(\\/A\)*\s*)* As you can see I have the group (.*?) inside the inner loop (everything)* If I print out $5 I get a result. How do I get the others? i.e. A TITLE= 66% verb: To come near or nearer to, or to set about a task HREF=dictKS/dictKS00.html#APPROACH TARGET=dictionary APPROACH#1/A=1 A TITLE= tags: Modif Strng Actv Time* Ovrst HREF=dictKS/dictKS18.html#SPEED TARGET=dictionary SPEED#1/A=1 / A should match twice. The thing is I need to find both matching internal values Thus, APPROACH#1 and #SPEED1 should be returned. Does anyone know how I do this? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
How to conditionally substitute in files?
This works: perl -i.bak -ple s/class/xybpublicabc/g Migration.cs However, when there are no matches, it still creates a new .bak file. How can we not change the date time on a file if there are no substitutions make?
Re: hash keys
Paul Lalli wrote: On Jun 12, 12:15 am, [EMAIL PROTECTED] (Beast) wrote: Why this following code has not working as expected? print Number of element(s) : . sprintf(%10d, keys(%hash) ) . \n; The keys() function does two different things, depending on context. In scalar context, it returns the number of key/value pairs in the hash. In list context, it returns a list of the keys. You probably knew that, but didn't realize that you're using it in a list context here. The arguments to a function are a list, $ perl -le'print prototype CORE::sprintf' $@ The *second* argument to this *particular* function is a list. and so Perl is expecting a list of values to be passed to sprintf(). A scalar and a list. The first argument is interpreted in scalar context: $ perl -le'@x = a .. z; print sprintf @x' 26 $ perl -le'print sprintf a .. z' 1E0 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: How to conditionally substitute in files?
Siegfried Heintze (Aditi) wrote: This works: perl -i.bak -ple s/class/xybpublicabc/g Migration.cs However, when there are no matches, it still creates a new .bak file. How can we not change the date time on a file if there are no substitutions make? You have to code it that way explicitly yourself, something like (UNTESTED): my $file = 'Migration.cs'; open my $IN, '', $file or die Cannot open '$file' $!; open my $OUT, '', $file.new or die Cannot open '$file.new' $!; my $changed; while ( $IN ) { $changed += s/class/xybpublicabc/g; print $OUT; } close $OUT; close $IN; if ( $changed ) { rename $file, $file.bak or die Cannot rename '$file' $!; rename $file.new, $file or die Cannot rename '$file.new' $!; else { unlink $file.new or die Cannot unlink '$file.new' $!; } __END__ 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: Meaning of [EMAIL PROTECTED]
Jeff Peng schreef: sundeep.sn@: What does the following piece of code mean? my @temp1; my @temp2; $cnt=0; $temp2[$cnt] = [EMAIL PROTECTED]; What is the kind of data stored in $tempFieldNames[$information] ? [EMAIL PROTECTED] means creating an anonymous array. It creates an anonymous array *and* returns a reference to it. This anonymous's elements are the ones of @temp1. The elements of the anonymous array are *copies* of the ones of @temp1. An anonymous array is a scalar, this scalar is assigned to $temp2[$cnt]. An anonymous array is just an array with no name. A reference is a scalar. See perlref and perlreftut. -- Affijn, Ruud Gewoon is een tijger. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: How to conditionally substitute in files?
Thanks John! I to edit it a little but it works! Can someone explain to why I have to remove the $ from $IN and $OUT and remove the my in my $IN and my $OUT to make it work? Thanks, Siegfried -Original Message- From: John W. Krahn [mailto:[EMAIL PROTECTED] Sent: Thursday, June 12, 2008 1:08 PM To: Perl Beginners Subject: Re: How to conditionally substitute in files? Siegfried Heintze (Aditi) wrote: This works: perl -i.bak -ple s/class/xybpublicabc/g Migration.cs However, when there are no matches, it still creates a new .bak file. How can we not change the date time on a file if there are no substitutions make? You have to code it that way explicitly yourself, something like (UNTESTED): my $file = 'Migration.cs'; open my $IN, '', $file or die Cannot open '$file' $!; open my $OUT, '', $file.new or die Cannot open '$file.new' $!; my $changed; while ( $IN ) { $changed += s/class/xybpublicabc/g; print $OUT; } close $OUT; close $IN; if ( $changed ) { rename $file, $file.bak or die Cannot rename '$file' $!; rename $file.new, $file or die Cannot rename '$file.new' $!; else { unlink $file.new or die Cannot unlink '$file.new' $!; } __END__ 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/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: looping 2 times through 5000 differs from 5000 times through 2
Jenda Krynicky wrote: From: Rob Dixon [EMAIL PROTECTED] oldgeezer wrote: foreach my $entry (uniq @IK){ foreach my $line(@DATA) { # Note /;$entry;/ takes longer than # /$entry;/ and that takes longer than /$entry/ # But /$entry/ also splits remarks_entries. # So I need the trailing ';' because they # are not in the remarks_entries # Appending the i, like: /$entry/i slows # down too. I don't need it. # Prepending m, like m/$entry/ # does not change anything (timewise). # For the average person /$entry;/ is fastest if($line=~ /$entry;/) { splitline($line); [EMAIL PROTECTED] changes when I splitline #next; don't do this. It makes it slower }; }; }; Your comments are fine, but they have obscured your code structure. How about # Note /;$entry;/ takes longer than /$entry;/ and that takes # longer than /$entry/ But /$entry/ also splits # remarks_entries. So I need the trailing ';' because they # are not in the remarks_entries. # # Appending the i, like: /$entry/i slows down too. I don't # need it. Prepending m, like m/$entry/ does not change # anything (timewise). For the average person /$entry;/ is # fastest # foreach my $entry (uniq @IK) { foreach my $line (@DATA) { if ($line=~ /$entry;/) { splitline($line); # @IK changes when I splitline #next; don't do this. It makes it slower } } } But even then I have issues with what your comments say. First of all you are obsessed with speed over function. A programmer's primary duty is to make things that work, and look like they work; it is only a secondary consideration to make things faster if they turn out to be too slow. Agreed. OTOH, in this case one might actually make it even quicker using qr//: foreach my $entry (uniq @IK) { my $entry_re = qr/$entry;/; foreach my $line (@DATA) { if ($line=~ $entry_re) { splitline($line); # @IK changes when I splitline #next; don't do this. It makes it slower } } } Another thing ... if splitline($line) indeed does change @IK (which is a bad thing, it should not modify something behind the scenes) do you expect the outer foreach to note that? I hope not, in any case, it doesn't. Correct. But it is a task of splitline to change (add data) to @IK. This is not 'behind the scene'. The outer foreach should operate on not changing data of an array that at entry of the foreach happens to be the same as the (at that moment current) @IK (stripped of double entries) I should have written it like: my @SUBSET=uniq (@IK); foreach my $entry in (@SUBSET) { do_something} But your remark is very valid. Especially if the $entry is long and is actually a regexp and not a string of letters. Of course if it's not meant to be a regexp you should use my $entry_re = qr/\Q$entry\E;/; Ahhh. This qr// is new to me. I've read the perlop now completely (needed to understand your line anyway). Until now I did read only the beginning of perlop because I thought it only handled about operator precedence. $entry can be many characters. I am not on Linux at the moment, because the phone of my daughter breaks in at IP adresses and causes my linux browser to run away. I still got to figure out what happens there. So I cannot give you the max line length that a unity data base allows, neither can I calculate what the longest line is in my DB. I reckon that to be around 300 to 400 characters. The lines are latin1 to be precise and closed with LF. On the web it may also be CRLF. That depends on the server. It is not a regexp. Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery Thanks. Rob. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
many variables and one value
Hi there, I am trying to get the following variables to all equal 1. what is the easiest way to do that/ $loginCount, $areaCount, $stateCount, $cityCount, $elementCount = 1; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: many variables and one value
On Fri, Jun 13, 2008 at 9:04 AM, Noah [EMAIL PROTECTED] wrote: Hi there, I am trying to get the following variables to all equal 1. what is the easiest way to do that/ $loginCount, $areaCount, $stateCount, $cityCount, $elementCount = 1; $loginCount = $areaCount = $stateCount = $cityCount = $elementCount = 1; -- Jeff Peng - [EMAIL PROTECTED] Professional Squid supports in China http://www.ChinaSquid.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: many variables and one value
On Thu, Jun 12, 2008 at 21:04, Noah [EMAIL PROTECTED] wrote: Hi there, I am trying to get the following variables to all equal 1. what is the easiest way to do that/ $loginCount, $areaCount, $stateCount, $cityCount, $elementCount = 1; snip $loginCount = $areaCount = $stateCount = $cityCount = $elementCount = 1; But the fact that you named them all count is a sign that you might want a hash instead: my %count; @count{qw/login area state city element/} = (1,1,1,1,1); -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: How to conditionally substitute in files?
Siegfried Heintze (Aditi) wrote: From: John W. Krahn [mailto:[EMAIL PROTECTED] You have to code it that way explicitly yourself, something like (UNTESTED): my $file = 'Migration.cs'; open my $IN, '', $file or die Cannot open '$file' $!; open my $OUT, '', $file.new or die Cannot open '$file.new' $!; my $changed; while ( $IN ) { $changed += s/class/xybpublicabc/g; print $OUT; } close $OUT; close $IN; if ( $changed ) { rename $file, $file.bak or die Cannot rename '$file' $!; rename $file.new, $file or die Cannot rename '$file.new' $!; else { unlink $file.new or die Cannot unlink '$file.new' $!; } Thanks John! I to edit it a little but it works! Can someone explain to why I have to remove the $ from $IN and $OUT and remove the my in my $IN and my $OUT to make it work? Older versions of Perl could not use lexical variables for filehandles. 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: many variables and one value
Noah wrote: Hi there, Hello, I am trying to get the following variables to all equal 1. what is the easiest way to do that/ $loginCount, $areaCount, $stateCount, $cityCount, $elementCount = 1; $_ = 1 for my ( $loginCount, $areaCount, $stateCount, $cityCount, $elementCount ); 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: many variables and one value
Chas. Owens wrote: On Thu, Jun 12, 2008 at 21:04, Noah [EMAIL PROTECTED] wrote: Hi there, I am trying to get the following variables to all equal 1. what is the easiest way to do that/ $loginCount, $areaCount, $stateCount, $cityCount, $elementCount = 1; snip $loginCount = $areaCount = $stateCount = $cityCount = $elementCount = 1; But the fact that you named them all count is a sign that you might want a hash instead: my %count; @count{qw/login area state city element/} = (1,1,1,1,1); my %count = map { $_ = 1 } qw/ login area state city element /; my %count; $_ = 1 for @count{ qw/ login area state city element / }; 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/
Expect.pm passing $exp to subroutine
Hi, thank you again list members for the quick response to my last question. I am using the I am trying to figure out to pass my $exp to the subroutine grabConfig. $exp is the variable of my expect object. line 169 is $patidx = $exp-expect($timeout, [$prompt]); here is the error message: Please Enter Selection: Can't call method expect on an undefined value at ./get.config.pl line 167. here are snippets from my code: snip --- # send element number while ($elementCount $elementUpperLimit) { $prompt = $blah; $exp-send($elementCount); grabConfig; $elementCount++; } sub grabConfig { $prompt = [EMAIL PROTECTED]; $patidx = $exp-expect($timeout, [$prompt]); line 169 $read = $exp-before(); #get hostname $read =~ /^@([^]+)\s/; $hostname = $1; $hostname = tr/[a-z]/[A-Z]/; $outputFilename = $hostname.config.txt; #delete saved configuraiton file unlink ($outputFilename); # open new configuration file open (OUTPUT, $outputFilename); snip -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Expect.pm passing $exp to subroutine ** line number correction
Hi, thank you again list members for the quick response to my last question. I am using the I am trying to figure out to pass my $exp to the subroutine grabConfig. $exp is the variable of my expect object. line 167 is $patidx = $exp-expect($timeout, [$prompt]); here is the error message: Please Enter Selection: Can't call method expect on an undefined value at ./get.config.pl line 167. here are snippets from my code: snip --- # send element number while ($elementCount $elementUpperLimit) { $prompt = $blah; $exp-send($elementCount); grabConfig; $elementCount++; } sub grabConfig { $prompt = [EMAIL PROTECTED]; $patidx = $exp-expect($timeout, [$prompt]); line 169 $read = $exp-before(); #get hostname $read =~ /^@([^]+)\s/; $hostname = $1; $hostname = tr/[a-z]/[A-Z]/; $outputFilename = $hostname.config.txt; #delete saved configuraiton file unlink ($outputFilename); # open new configuration file open (OUTPUT, $outputFilename); snip -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: many variables and one value
John W. Krahn wrote: $_ = 1 for my ( $loginCount, $areaCount, $stateCount, $cityCount, $elementCount ); my ( $loginCount, $areaCount, $stateCount, $cityCount, $elementCount ) = map 1, 1..5; -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: many variables and one value
On Thu, Jun 12, 2008 at 21:45, Gunnar Hjalmarsson [EMAIL PROTECTED] wrote: John W. Krahn wrote: $_ = 1 for my ( $loginCount, $areaCount, $stateCount, $cityCount, $elementCount ); my ( $loginCount, $areaCount, $stateCount, $cityCount, $elementCount ) = map 1, 1..5; my ( $loginCount, $areaCount, $stateCount, $cityCount, $elementCount ) = (1) x 5; -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: many variables and one value
Chas. Owens wrote: On Thu, Jun 12, 2008 at 21:45, Gunnar Hjalmarsson [EMAIL PROTECTED] wrote: John W. Krahn wrote: $_ = 1 for my ( $loginCount, $areaCount, $stateCount, $cityCount, $elementCount ); my ( $loginCount, $areaCount, $stateCount, $cityCount, $elementCount ) = map 1, 1..5; my ( $loginCount, $areaCount, $stateCount, $cityCount, $elementCount ) = (1) x 5; LOL ;) I hope by easiest way he meant the most cost effective method that falls out the bottom of a tennis match ;) ...impressive...very impressive. Thanks, Steve -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: many variables and one value
On Fri, Jun 13, 2008 at 10:35 AM, Steve Bertrand [EMAIL PROTECTED] wrote: I hope by easiest way he meant the most cost effective method that falls out the bottom of a tennis match ;) ...impressive...very impressive. What's the most complicated way to do it on the other hand? :-) -- Jeff Peng - [EMAIL PROTECTED] Professional Squid supports in China http://www.ChinaSquid.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Expect.pm passing $exp to subroutine ** line number correction
Noah wrote: Hi, Hello, thank you again list members for the quick response to my last question. I am using the I am trying to figure out to pass my $exp to the subroutine grabConfig. $exp is the variable of my expect object. line 167 is $patidx = $exp-expect($timeout, [$prompt]); here is the error message: Please Enter Selection: Can't call method expect on an undefined value at ./get.config.pl line 167. here are snippets from my code: snip --- # send element number while ($elementCount $elementUpperLimit) { $prompt = $blah; $exp-send($elementCount); perldoc -q What.s wrong with always quoting ..vars.? $prompt = $blah; $exp-send( $elementCount ); grabConfig; grabConfig(); perldoc perlsub $elementCount++; } sub grabConfig { $prompt = [EMAIL PROTECTED]; my $prompt = qr/[EMAIL PROTECTED]/; $patidx = $exp-expect($timeout, [$prompt]); line 169 According to the documentation: QUOTE $object-expect($timeout, @match_patterns) /QUOTE The second argument to expect() should not be an array reference. http://search.cpan.org/~rgiersig/Expect-1.21/Expect.pod $read = $exp-before(); #get hostname $read =~ /^@([^]+)\s/; $hostname = $1; You should not use the numerical variables unless the match was successful: $read =~ /^@([^]+)\s/ and $hostname = $1; Or: ( $hostname ) = $read =~ /^@([^]+)\s/; $hostname = tr/[a-z]/[A-Z]/; Why are you translating '[' to '[' and ']' to ']'? $hostname = tr/a-z/A-Z/; Or: $read =~ /^@([^]+)\s/ and $hostname = uc $1; $outputFilename = $hostname.config.txt; #delete saved configuraiton file unlink ($outputFilename); You should verify that unlink worked correctly: unlink $outputFilename or warn Cannot unlink '$outputFilename' $!; But you don't really need to unlink the file as you are opening it read-only which will remove the previous contents upon opening. # open new configuration file open (OUTPUT, $outputFilename); You should *always* verify that the file opened correctly: open OUTPUT, '', $outputFilename or die Cannot open '$outputFilename' $!; 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: Expect.pm passing $exp to subroutine ** line number correction
John W. Krahn wrote: Noah wrote: #delete saved configuraiton file unlink ($outputFilename); You should verify that unlink worked correctly: unlink $outputFilename or warn Cannot unlink '$outputFilename' $!; But you don't really need to unlink the file as you are opening it read-only which will remove the previous contents upon opening. Correction: You are opening the file *write-only* which will remove the previous contents upon opening. 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: many variables and one value
On Thu, Jun 12, 2008 at 22:44, Jeff Peng [EMAIL PROTECTED] wrote: On Fri, Jun 13, 2008 at 10:35 AM, Steve Bertrand [EMAIL PROTECTED] wrote: I hope by easiest way he meant the most cost effective method that falls out the bottom of a tennis match ;) ...impressive...very impressive. What's the most complicated way to do it on the other hand? :-) I don't have time to do it justice, but this is complicated enough for now: #!/usr/bin/perl use strict; use warnings; my ($loginCount, $areaCount, $stateCount, $cityCount, $elementCount) = (int sqrt sqrt int log ord uc qq pack ord rand sqrt exp or die) x 5; print lc=$loginCount ac=$areaCount sc=$stateCount cc=$cityCount ec=$elementCount\n; -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/