AW: Kindly explain special variable $|
sanket vaidya sanket.vai...@patni.com asked: It would be great if some of you write a simple code which has two different outputs for $| = 0 $| = 1 to demonstrate the difference. Try this with different values for $| #!/usr/bin/perl -w use strict; $| = 1; for ( 1..20 ){ print .; warn ! unless $i % 5; sleep 1; } print \n; __END__ HTH, Thomas -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Kindly explain special variable $|
-Original Message- From: Thomas Bätzler [mailto:t.baetz...@bringe.com] Sent: Thursday, May 28, 2009 11:57 AM To: beginners@perl.org Cc: sanket vaidya Subject: AW: Kindly explain special variable $| sanket vaidya sanket.vai...@patni.com asked: It would be great if some of you write a simple code which has two different outputs for $| = 0 $| = 1 to demonstrate the difference. Try this with different values for $| #!/usr/bin/perl -w use strict; $| = 1; for ( 1..20 ){ print .; warn ! unless $i % 5; sleep 1; } print \n; __END__ HTH, Thomas Used your code as below: use strict; $| = 1; for my $i ( 1..20 ){ print .; warn i = $i ! unless $i % 5; sleep 1; } This code gave some vague picture in my mind about flushing. To summarize When we write some data, the data is not written (to terminal or file) instantly, but is collected in buffer is only written when the buffer is full. Once the buffer is full, the data is written thereafter buffer is erased. This is known as flushing. Setting $| = 1 flushes the buffer as soon as it receives a data. So the buffer doesn't wait to collect specific amounts of data before flushing. Kindly elaborate this correct me if I am wrong. Regards, Sanket Vaidya _ This e-mail message may contain proprietary, confidential or legally privileged information for the sole use of the person or entity to whom this message was originally addressed. Any review, e-transmission dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you have received this e-mail in error kindly delete this e-mail from your records. If it appears that this mail has been forwarded to you without proper authority, please notify us immediately at netad...@patni.com and delete this mail. _ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Range Operator Question
Hi, I came across this statement about 'range' operators somewhere. There is very little difference between $x..$y and $x...$y, and if the second operand is a constant then they are identical. What is the difference? Kindly explain with example. Thanks Regards, Sanket Vaidya _ This e-mail message may contain proprietary, confidential or legally privileged information for the sole use of the person or entity to whom this message was originally addressed. Any review, e-transmission dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you have received this e-mail in error kindly delete this e-mail from your records. If it appears that this mail has been forwarded to you without proper authority, please notify us immediately at netad...@patni.com and delete this mail. _
Re: Range Operator Question
On Thu, May 28, 2009 at 07:51, sanket vaidya sanket.vai...@patni.com wrote: Hi, I came across this statement about 'range' operators somewhere. There is very little difference between $x..$y and $x...$y, and if the second operand is a constant then they are identical. What is the difference? Kindly explain with example. snip In list context the ... operator is the same as the .. operator. In scalar context, well perlop[1] says it better than I could: In scalar context, .. returns a boolean value. The operator is bistable, like a flip‐flop, and emulates the line‐range (comma) operator of sed, awk, and various editors. Each .. operator maintains its own boolean state. It is false as long as its left operand is false. Once the left operand is true, the range operator stays true until the right operand is true, AFTER which the range operator becomes false again. It doesn’t become false till the next time the range operator is evaluated. It can test the right operand and become false on the same evaluation it became true (as in awk), but it still returns true once. If you don’t want it to test the right operand till the next evaluation, as in sed, just use three dots (...) instead of two. In all other regards, ... behaves just like .. does. 1. http://perldoc.perl.org/perlop.html#Range-Operators -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Kindly explain special variable $|
On Thu, May 28, 2009 at 06:23, sanket vaidya sanket.vai...@patni.com wrote: snip This code gave some vague picture in my mind about flushing. To summarize When we write some data, the data is not written (to terminal or file) instantly, but is collected in buffer is only written when the buffer is full. Once the buffer is full, the data is written thereafter buffer is erased. This is known as flushing. Setting $| = 1 flushes the buffer as soon as it receives a data. So the buffer doesn't wait to collect specific amounts of data before flushing. Kindly elaborate this correct me if I am wrong. snip That is it. -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: intermediate perl list???
John == John W Krahn jwkr...@shaw.ca writes: John ITYM: comp.lang.perl.misc John comp.lang.perl was killed off many years ago. Where many is 15 now. 1994 if I recall. I was made the comp.lang.perl.announce moderator in the same action. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/ Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
suppressing Use of uninitialized value in pattern match (m//)
How can I suppress the first Use of uninitialized value in pattern match (m//) warning message. code and output are below. code # cat ./fix_archive.pl #!/usr/bin/perl use warnings; use strict; my @files = * unless /.mbox^/; foreach my $file (@files) { print $file . \n; } code --- here is the output # ./fix_archive.pl Use of uninitialized value in pattern match (m//) at ./fix_archive.pl line 6. add_members arch b4b5-archfix change_pw check_db check_perms cleanarch clone_member config_list convert.py convert.pyc discard dumpdb export.py -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: suppressing Use of uninitialized value in pattern match (m//)
admin2 wrote: How can I suppress the first Use of uninitialized value in pattern match (m//) warning message. code and output are below. Don't suppress a message, but fix the problem. my @files = * unless /.mbox^/; This is the only pattern match in your script, so that is the line with the problem, don't you think? Line number 6, as the message told you. You could probably change it to my @files = grep !m{[.]mbox\z}, *; (untested) -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Parsing TXT document and output to XML
On 5/27/09 Wed May 27, 2009 3:27 PM, Stephen Reese rsre...@gmail.com scribbled: List, I've been working on a method to parse a PDF or TXT document and output the results to XML over at Experts Exchange. http://www.experts-exchange.com/Programming/Languages/Scripting/Perl/Q_2443963 0.html You may view the attached document or if the mailing list doesn't allow here is a copy of the document I would like to parse: http://filedb.experts-exchange.com/incoming/2009/05_w22/143310/XenApp-Secure-G ateway-Server-VL0.txt Basically I would like to take the following code and modify it to parse a TXT instead of a PDF document: #!/usr/bin/perl use strict; use warnings; use Data::Dumper; use CAM::PDF; my $pdf = CAM::PDF-new('XenApp_WebInterface_Server_VL04.pdf'); my $text; foreach (1..$pdf-numPages) { $text .= $pdf-getPageText($_); } while($text =~ /Vulnerability Key:\s* (\S+)\s+STIG ID:\s* (\S+)\s+Release Number:\s* (\S+)\s+Status:\s* (\S+)\s+Short Name:\s* (\S+)\s+Long Name:\s* (\S+)\s+IA Controls:\s* (\S+)\s+Categories:\s* (\S+)\s+Effective Date:\s* (\S+)\s+Condition:\s* (\S+)\s+Policy:\s* (\S+)/g) { print Vuln Vulnerability_Key_$1/Vulnerability_Key_ STIG_ID$2/STIG_ID_ Release_Number_$3/Release_Number_ Status_$4/Status_ Short_Name_$5/Short_Name_ Long_Name_$6/Long_Name_ IA_Controls_IA_ControlID$7ID/IA_Control/IA_Controls_ Categories_$8/Categories_ Effective_Date_$9/Effective_Date_ Condition_subitemtitle$10/titledata/data/subitem/Condition_ Policy_$11/Policy_ /Vuln\n; } You have two basic choices: 1. Read the whole file into a variable and use the regular expression as above to match multiple lines, extract the information, and print it. 2. Read the file line-by-line, save the relevant data, and print the data when you have a complete set or at the end of the program. A third choice if your data permits would be to set the input record separator ($/) to the value that separates your records and read multiple lines as a record. I don't think this will work in your case. Here is an example of approach 2: #!/usr/local/bin/perl use strict; use warnings; my @keys = ( 'Vulnerability Key', 'STIG ID', 'Release Number', 'Status', 'Short Name', 'Long Name', 'IA Controls', 'Categories', 'Effective Date', 'Condition', 'Policy' ); my( %keys, %tags ); $keys{$_} = 1 for @keys; $tags{$_} = $_ . '_' for @keys; $tags{$_} =~ s/ /_/g for @keys; my $file = 'XenApp Secure_Gateway_Server_VL04.txt'; open( my $fh, '', $file) or die(Can't open $file: $!); my %record = map { $_, '' } @keys; while( my $line = $fh ) { chomp($line); if( $line =~ m{ \A (.+?) : \s* (\S+) }x ) { $record{$1} = $2 if $keys{$1}; if( $1 eq $keys[$#keys] ) { print Vuln\n; print $tags{$_}$record{$_}/$tags{$_}\n for @keys; print /Vuln\n; %record = map { $_, '' } @keys; } } } ... which produces for your input: Vuln Vulnerability_Key_V0018219/Vulnerability_Key_ STIG_ID_CTX0700/STIG_ID_ Release_Number_1/Release_Number_ Status_Working/Status_ Short_Name_Secure/Short_Name_ Long_Name_Secure/Long_Name_ IA_Controls_ECSC-1/IA_Controls_ Categories_4.4/Categories_ Effective_Date_/Effective_Date_ Condition_/Condition_ Policy_All/Policy_ /Vuln ... You may want to add error checking to the case where some keys are missing. Note that your regular expression will only extract the first word of the value, and your data in some cases has more than that on a line. You can change this by changing the RE to: if( $line =~ m{ \A (.+?) : \s* (.*?) \s* \z }x ) { -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Range Operator Question
-Original Message- From: Chas. Owens [mailto:chas.ow...@gmail.com] Sent: Thursday, May 28, 2009 5:55 PM To: sanket vaidya Cc: beginners@perl.org Subject: Re: Range Operator Question On Thu, May 28, 2009 at 07:51, sanket vaidya sanket.vai...@patni.com wrote: Hi, I came across this statement about 'range' operators somewhere. There is very little difference between $x..$y and $x...$y, and if the second operand is a constant then they are identical. What is the difference? Kindly explain with example. snip In list context the ... operator is the same as the .. operator. In scalar context, well perlop[1] says it better than I could: In scalar context, .. returns a boolean value. The operator is bistable, like a flip-flop, and emulates the line-range (comma) operator of sed, awk, and various editors. Each .. operator maintains its own boolean state. It is false as long as its left operand is false. Once the left operand is true, the range operator stays true until the right operand is true, AFTER which the range operator becomes false again. It doesn't become false till the next time the range operator is evaluated. It can test the right operand and become false on the same evaluation it became true (as in awk), but it still returns true once. If you don't want it to test the right operand till the next evaluation, as in sed, just use three dots (...) instead of two. In all other regards, ... behaves just like .. does. 1. http://perldoc.perl.org/perlop.html#Range-Operators -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. Can anyone write few simple codes explaining the behavior that Chas mentioned, So that I can explore the codes for getting better picture? _ This e-mail message may contain proprietary, confidential or legally privileged information for the sole use of the person or entity to whom this message was originally addressed. Any review, e-transmission dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you have received this e-mail in error kindly delete this e-mail from your records. If it appears that this mail has been forwarded to you without proper authority, please notify us immediately at netad...@patni.com and delete this mail. _ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Range Operator Question
-Original Message- From: sanket vaidya [mailto:sanket.vai...@patni.com] Sent: Friday, May 29, 2009 9:20 AM To: 'beginners@perl.org' Subject: RE: Range Operator Question -Original Message- From: Chas. Owens [mailto:chas.ow...@gmail.com] Sent: Thursday, May 28, 2009 5:55 PM To: sanket vaidya Cc: beginners@perl.org Subject: Re: Range Operator Question On Thu, May 28, 2009 at 07:51, sanket vaidya sanket.vai...@patni.com wrote: Hi, I came across this statement about 'range' operators somewhere. There is very little difference between $x..$y and $x...$y, and if the second operand is a constant then they are identical. What is the difference? Kindly explain with example. snip In list context the ... operator is the same as the .. operator. In scalar context, well perlop[1] says it better than I could: In scalar context, .. returns a boolean value. The operator is bistable, like a flip-flop, and emulates the line-range (comma) operator of sed, awk, and various editors. Each .. operator maintains its own boolean state. It is false as long as its left operand is false. Once the left operand is true, the range operator stays true until the right operand is true, AFTER which the range operator becomes false again. It doesn't become false till the next time the range operator is evaluated. It can test the right operand and become false on the same evaluation it became true (as in awk), but it still returns true once. If you don't want it to test the right operand till the next evaluation, as in sed, just use three dots (...) instead of two. In all other regards, ... behaves just like .. does. 1. http://perldoc.perl.org/perlop.html#Range-Operators -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. Can anyone write few simple codes explaining the behavior that Chas mentioned, So that I can explore the codes for getting better picture? Regards, Sanket Vaidya _ This e-mail message may contain proprietary, confidential or legally privileged information for the sole use of the person or entity to whom this message was originally addressed. Any review, e-transmission dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you have received this e-mail in error kindly delete this e-mail from your records. If it appears that this mail has been forwarded to you without proper authority, please notify us immediately at netad...@patni.com and delete this mail. _ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
List of perl functions that work on LINUX not in Windows
Hi all, Kindly provide a list of perl functions that work on LINUX but not on windows. Also provide the list of functions that behave differently on Windows LINUX. This not project requirement. I just want to explore the functions on LINUX. So far I have been using ActiveState Perl on Windows. Thanks Regards, Sanket Vaidya _ This e-mail message may contain proprietary, confidential or legally privileged information for the sole use of the person or entity to whom this message was originally addressed. Any review, e-transmission dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you have received this e-mail in error kindly delete this e-mail from your records. If it appears that this mail has been forwarded to you without proper authority, please notify us immediately at netad...@patni.com and delete this mail. _
Re: Range Operator Question
On Thu, May 28, 2009 at 23:49, sanket vaidya sanket.vai...@patni.com wrote: snip Can anyone write few simple codes explaining the behavior that Chas mentioned, So that I can explore the codes for getting better picture? snip #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @a = 1 ... 10; print normal flip flop behavior:\n, the .. operator\n; for my $n (@a) { if ($n == 3 .. $n == 6) { print \t$n\n; } } print \nthe ... operator\n; for my $n (@a) { if ($n == 3 ... $n == 6) { print \t$n\n; } } print \nbehavior when the condition is true for both tests at the same time\n, the .. operator\n; for my $n (@a) { if ($n == 3 .. $n == 3) { print \t$n\n; } } print \nthe ... operator\n; for my $n (@a) { if ($n == 3 ... $n == 3) { print \t$n\n; } } -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: readdir() question
Hi Here (.) means current directory (..) means parent directory But you are getting (..) and (...) Because you kept one (.) in map{{$_.\n} Remove the (.) after $_ you will get correct output Thanks Ajay -Original Message- From: Telemachus [mailto:telemac...@arpinum.org] Sent: Monday, May 25, 2009 4:30 AM To: beginners@perl.org Subject: Re: readdir() question On Mon May 25 2009 @ 4:34, sanket vaidya wrote: Hi all, Kindly look at the code below: use warnings; use strict; opendir(DIR, D:\\test) || die can't opendir: $!; my @dots = readdir(DIR); print map{$_.\n}...@dots; .. ... Test1 Test2 Test3 Where Test1, Test2, Test3 are files within test directory. Apart from that I also got dots (2 in 1st line 3 in 2nd line). I know that '..' stands for parent directory what does '...' mean? Your real output must have looked more like this: .. ... Test1. Test2. Test3. You put a period ('.') near the end of your call to print, so instead of seeing '.' and '..' (current and parent directory), you're seeing '..' and '...' (current and parent directory plus the period). In perldoc of readdir() I am unable to follow below line. Can anyone explain me the below line with example? 'If you're planning to filetest the return values out of a readdir http://perldoc.perl.org/functions/readdir.html , you'd better prepend the directory in question. Otherwise, because we didn't chdir http://perldoc.perl.org/functions/chdir.html there, it would have been testing the wrong file.' Consider this: use strict; use warnings; opendir(my $dh, '/home/telemachus/practice') || die can't opendir: $!; my @contents = readdir($dh); my @files = grep { -f /home/telemachus/practice/$_ } @contents; my @noprepend = grep { -f $_ } @contents; print With prepending:\n; print \t$_\n for @files; print Without prepending:\n; print \t$_\n for @noprepend; The first grep prepends (adds at the beginning) the path to each file. If you don't do that, you're testing for files in the directory where you call the script (or wherever the script happens to be, if you've changed directory at some point). Change the path to something reasonable for your system (in both the call to opendir and the my @files line) and compare the output you get for the two different uses of grep. Hope this helps, T -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: List of perl functions that work on LINUX not in Windows
On Fri, May 29, 2009 at 00:30, sanket vaidya sanket.vai...@patni.com wrote: snip Kindly provide a list of perl functions that work on LINUX but not on windows. Also provide the list of functions that behave differently on Windows LINUX. This not project requirement. I just want to explore the functions on LINUX. So far I have been using ActiveState Perl on Windows. snip This is what perldoc perlport[1] is for. 1. http://perldoc.perl.org/perlport.html -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/