perl.beginners.cgi Weekly list FAQ posting
NAME beginners-faq - FAQ for the beginners-cgi mailing list 1 - Administriva 1.1 - I'm not subscribed - how do I subscribe? Send mail to [EMAIL PROTECTED] You can also specify your subscription email address by sending email to (assuming [EMAIL PROTECTED] is your email address): [EMAIL PROTECTED]. 1.2 - How do I unsubscribe? Now, why would you want to do that? Send mail to [EMAIL PROTECTED], and wait for a response. Once you reply to the response, you'll be unsubscribed. If that doesn't work, find the email address which you are subscribed from and send an email like the following (let's assume your email is [EMAIL PROTECTED]): [EMAIL PROTECTED] 1.3 - There is too much traffic on this list. Is there a digest? Yes. To subscribe to the digest version of this list send an email to: [EMAIL PROTECTED] To unsubscribe from the digest, send an email to: [EMAIL PROTECTED] 1.4 - Is there an archive on the web? Yes, there is. It is located at: http://archive.develooper.com/beginners-cgi%40perl.org/ 1.5 - How can I get this FAQ? This document will be emailed to the list once a month, and will be available online in the archives, and at http://beginners.perl.org/ 1.6 - I don't see something in the FAQ, how can I make a suggestion? Send an email to [EMAIL PROTECTED] with your suggestion. 1.7 - Is there a supporting website for this list? Yes, there is. It is located at: http://beginners.perl.org/ 1.8 - Who do I complain to? Complaints can be sent to [EMAIL PROTECTED] 1.9 - Who currently maintains the FAQ? Kevin Meltzer, who can be reached at the email address (for FAQ suggestions only) in question 1.6 1.10 - Who will maintain peace and flow on the list? Casey West, Kevin Meltzer and Ask Bjoern Hansen currently carry large, yet padded, clue-sticks to maintain peace and order on the list. If you are privately emailed by one of these folks for flaming, being off-topic, etc... please listen to what they say. If you see a message sent to the list by one of these people saying that a thread is closed, do not continue to post to the list on that thread! If you do, you will not only meet face to face with a XQJ-37 nuclear powered pansexual roto-plooker, but you may also be taken off of the list. These people simply want to make sure the list stays topical, and above-all, useful to Perl/CGI beginners. 1.11 - When was this FAQ last updated? Feb 04, 2004 2 - Questions about the 'beginners-cgi' list. 2.1 - What is the list for? A list for beginning Perl programmers to ask questions in a friendly atmosphere. The topic of the list is, of course, CGI with Perl. 2.2 - What is this list _not_ for? * SPAM * Homework * Solicitation * Things that aren't Perl related * Non Perl/CGI questions or issues * Lemurs 2.3 - Are there any rules? Yes. As with most communities, there are rules. Not many, and ones that shouldn't need to be mentioned, but they are. * Be nice * No flaming * Have fun 2.4 - What topics are allowed on this list? Basically, if it has to do with Perl/CGI , then it is allowed. If your question has nothing at all to do with Perl/CGI, it will likely be ignored. 2.5 - I want to help, what should I do? Subscribe to the list! If you see a question which you can give an idiomatic and Good answer to, answer away! If you do not know the answer, wait for someone to answer, and learn a little. 2.6 - Is there anything I should keep in mind while answering? We don't want to see 'RTFM'. That isn't very helpful. Instead, guide the beginner to the place in the FM they should R :) 2.7 - I don't want to post a question if it is in an FAQ. Where should I look first? Look in the FAQ! Get acquainted with the 'perldoc' utility, and use it. It can save everyone time if you look in the Perl FAQs first, instead of having a list of people refer you to the Perl FAQs :) You can learn about 'perldoc' by typing: perldoc perldoc At your command prompt. You can also view documentation online at: http://www.perldoc.com and http://www.perl.com 3 - Other Resources 3.1 - What other websites may be useful to a beginner ? * Perl.org - http://www.perl.org * Perl Home Page - http://www.perl.com * PerlMonks - http://www.perlmonks.org * Perldoc - http://www.perldoc.com * Perl Archives - http://www.perlarchives.com * NMS Archive - http://nms-cgi.sourceforge.net/ * Unofficial Perl Beginners' Site - http://perl-begin.berlios.de 3.2 - What resources may be harmful to a beginner? Beware of Perl4-like code-- You might find some script archives and unauthorized mirrors with old Perl4 versions of Selena Sol and Matt Wright scripts. Don't use those scripts. They are outdated and may even in some cases
Filtering CGI Variables
Hi all, I need some help. I have name/value parameters coming in from a web form that look something like this (blank lines added for clarity): firstname=bill lastname=stephenson q1=1 t1=y d1=something 1 p1=3.45 q2= t2=y d2=something 2 p2=1.90 q3= t3=y d3= p3= q4=1 t4=y d4=something 3 p4=12 q5= t5=y d5= p5= q6=3 t6=y d6=something 4 p6=1.22 id_number=1259 action=none I want to remove the groups of data that look like q3-p3 and q5-p5 (where q,d, and p are all empty, t will always have data) then re-number the groups that contain data in in at least one of the q,d, or p variables, then save them to a file that looks something like this: firstname=bill lastname=stephenson q1=1 t1=y d1=something 1 p1=3.45 q2= t2=y d2=something 2 p2=1.90 q3=1 t3=y d3=something 3 p3=12 q4=3 t4=y d4=something 4 p4=1.22 id_number=1259 action=none I'm having trouble with the logic that will accomplish this. It doesn't seem like it should be very hard to do, but I just can't seem to say it in perl. Below is a script that I've been playing with that does output what I want, but it's pretty clunky and probably not very efficient. There must be a better way. Thanks, Bill Stephenson # start code below # #!/usr/bin/perl use strict; use CGI qw/:standard/; use CGI::Carp('fatalsToBrowser'); # Create a new CGI Object for the form input my $Q = new CGI; # This represents how the app will receive data from the browser... #print this $Q-param('firstname' ,Bill); $Q-param('lastname' , Stephenson); #print this $Q-param('q1' ,); $Q-param('t1' , Y); $Q-param('d1' , 12); $Q-param('p1' , 12); #print this $Q-param('q2' , 13); $Q-param('t2' , Y); $Q-param('d2' , ); $Q-param('p2' , 13); #print this $Q-param('q3' , 16); $Q-param('t3' , Y); $Q-param('d3' , 16); $Q-param('p3' , ); #do NOT print this $Q-param('q4' , ); $Q-param('t4' , Y); $Q-param('d4' , ); $Q-param('p4' , ); #print this $Q-param('q5' , 15); $Q-param('t5' , Y); $Q-param('d5' , 15); $Q-param('p5' , 15); #do NOT print this $Q-param('q6' , ); $Q-param('t6' , Y); $Q-param('d6' , ); $Q-param('p6' , ); #print this $Q-param('q7' , 22); $Q-param('t7' , Y); $Q-param('d7' , ); $Q-param('p7' , 22); #do NOT print this $Q-param('q8' , ); $Q-param('t8' , Y); $Q-param('d8' , ); $Q-param('p8' , ); #print this $Q-param('q9' , ); $Q-param('t9' , Y); $Q-param('d9' , 1000); $Q-param('p9' , 1000); #do NOT print this $Q-param('q10' , ); $Q-param('t10' , Y); $Q-param('d10' , ); $Q-param('p10' , ); #print this $Q-param('send_email' , yes); $Q-param('doc_number' , 55); # This is what we want to print... # q1= # t1=Y # d1=12 # p1=12 # q2=13 # t2=Y # d2= # p2=13 # q3=16 # t3=Y # d3=16 # p3= # q4=15 # t4=Y # d4=15 # p4=15 # q5=22 # t5=Y # d5= # p5=22 # q6= # t6=Y # d6=1000 # p6=1000 # firstname=Bill # lastname=Stephenson # send_email=yes # doc_number=55 ### # put all the invoice parameters names # into an array... ### my @invoice_info = $Q-param; # Declare some variables my $line_counter=1; my $row_counter=1; my $total_rows=10; # first we print the numbered rows that contain some data... while ($line_counter $total_rows) { my $quantity=$Q-param(q$line_counter); my $tax=$Q-param(t$line_counter); my $description=$Q-param(d$line_counter); my $unit_price=$Q-param(p$line_counter); if ($quantity eq$description eq $unit_price eq ) { # do nothing } else { print q$row_counter=$quantity\n; print t$row_counter=$tax\n; print d$row_counter=$description\n; print p$row_counter=$unit_price\n; $row_counter++; } $line_counter++; } # end while loop # reset the line counter... $line_counter=1; # Then we get all the other parameters that are not numbered rows of data. foreach my $invoice_item (@invoice_info) { my $value = $Q-param($invoice_item); if ($invoice_item eq q$line_counter) { next; } if ($invoice_item eq t$line_counter) { next; } if ($invoice_item eq d$line_counter) { next; }
RE: Filtering CGI Variables
Bill Stephenson wrote: Hi all, I need some help. I have name/value parameters coming in from a web form that look something like this (blank lines added for clarity): firstname=bill lastname=stephenson q1=1 t1=y d1=something 1 p1=3.45 q2= t2=y d2=something 2 p2=1.90 q3= t3=y d3= p3= q4=1 t4=y d4=something 3 p4=12 q5= t5=y d5= p5= q6=3 t6=y d6=something 4 p6=1.22 id_number=1259 action=none I want to remove the groups of data that look like q3-p3 and q5-p5 (where q,d, and p are all empty, t will always have data) then re-number the groups that contain data in in at least one of the q,d, or p variables, then save them to a file that looks something like this: firstname=bill lastname=stephenson q1=1 t1=y d1=something 1 p1=3.45 q2= t2=y d2=something 2 p2=1.90 q3=1 t3=y d3=something 3 p3=12 q4=3 t4=y d4=something 4 p4=1.22 id_number=1259 action=none I'm having trouble with the logic that will accomplish this. It doesn't seem like it should be very hard to do, but I just can't seem to say it in perl. [snip code] Here's the approach I would take (not tested!) my %data; for (param()) { # loop through all parameters if (/^([qtdp])(\d+)$/) { my $prefix = $1; my $num = $2; $data{$num}{prefix} = param($_); } } Basically, this inverts the data so you have a hash like: ( '1' = { q = 1, t = 1, d = 'something 1', p = 3.45 }, '2' = { q = '', t = 2, d = 'something 2', p = 1.90 }, ... and so on } Now, let's find the groups that have something in q, d, or p: my @groups = grep @data{$_}{qw/q d p/} =~ /\S/, sort { $a = $b } keys %data; Now you can write those groups out, renumbering as you go: my $n = 0; for my $g (@groups) { $n++; print $_$n $g-{$_}\n for qw/q t d p/; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Perl oneliner to delete lines from a file
I want to write a command line perl 'script' to delete one or more lines from a file , by line number for eg in sed I can do the same in two steps cat FILENAME | sed -e '1,10d' FILENAME.TMP mv FILENAME.TMP FILENAME The above mechanism has a lot of pitfalls , like maintaining permissions , making sure FILENAME.TMP does not already exist etc. That is why I want to do it with perl -i but I dont want to write a full script for this , because I am going to run it on remote machines ( automated ) , and I cant ftp the script everywhere Any suggestions Thanks Ram -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
COMPLEX ARRAY STRUCTURE
Hi, $a = [ 'cn' = ['Barbara Jensen', 'Barbs Jensen'], 'sn' = 'Jensen', 'mail' = '[EMAIL PROTECTED]', 'objectclass' = ['top', 'person', 'organizationalPerson', 'inetOrgPerson' ], ]; I have this arrary structure, how should I read it? For example how do I acces to inetOrgPerson' value or Jesen value? Thanks LD -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: COMPLEX ARRAY STRUCTURE
Are you sure you want that top level to be an anonymous array instead of a hash? This would make more sense (see below for how to access the values). Note the {} brackets instead of the [] brackets. # my $a = {'cn' = ['Barbara Jensen', 'Barbs Jensen'], 'sn' = 'Jensen', 'mail' = '[EMAIL PROTECTED]', 'objectclass' = ['top', 'person', 'organizationalPerson', 'inetOrgPerson' ], }; print $a-{objectclass}-[3].\n; #inetOrgPerson print $a-{sn}.\n; #Jensen # -Original Message- From: Luis Daniel Lucio Quiroz [mailto:[EMAIL PROTECTED] Sent: Sunday, August 08, 2004 5:50 PM To: [EMAIL PROTECTED] Subject: COMPLEX ARRAY STRUCTURE Hi, $a = [ 'cn' = ['Barbara Jensen', 'Barbs Jensen'], 'sn' = 'Jensen', 'mail' = '[EMAIL PROTECTED]', 'objectclass' = ['top', 'person', 'organizationalPerson', 'inetOrgPerson' ], ]; I have this arrary structure, how should I read it? For example how do I acces to inetOrgPerson' value or Jesen value? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: COMPLEX ARRAY STRUCTURE
This seems to be the result of a Net::LDAP search. I would suggest you better read the perldoc for the module , there are methods to directly give you the cn, sn etc from the entry. That way even if you upgrade the module and if the structure of the object changes you wont have to change any of your code. Anyway If you *really* want to use messy calls to the object directly you could do this. To make it look less confusing you could just remove one level of a reference like my %hash = @{$a}; now access the elements at will $sn = $hash{sn}# If you are sure there can only be one sn if(ref($hash{cn}) eq 'ARRAY') { @listof_cn = @{$hash{cn}}; } else { $cn = $hash{cn}; } HTH Ram On Mon, 2004-08-09 at 06:19, Luis Daniel Lucio Quiroz wrote: Hi, $a = [ 'cn' = ['Barbara Jensen', 'Barbs Jensen'], 'sn' = 'Jensen', 'mail' = '[EMAIL PROTECTED]', 'objectclass' = ['top', 'person', 'organizationalPerson', 'inetOrgPerson' ], ]; I have this arrary structure, how should I read it? For example how do I acces to inetOrgPerson' value or Jesen value? Thanks LD -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Out of Topic :-Any perl training institutes in Bangalore
Hi All, I am new to perl. I would like to know if any one of you, aware of any training institutes in bangalore for perl training. I am also learning on my own, especially this group has been highly helpfull for beginners like me, but keeping in view of vastness of perl and limited time that we have for automation, i am enquiring about this. Thanks in Advance Regards Anand
Re: Perl oneliner to delete lines from a file
On Mon, 2004-08-09 at 07:34, Ramprasad A Padmanabhan wrote: I want to write a command line perl 'script' to delete one or more lines from a file , by line number Hi :-) If I understand correctly, you want to delete lines X to Y from a file, right? perl -i -ne 'print unless 1..10' file that should do the trick :-) The explanation follows: -i = in-place edit (you apparently already know what this does -n = for all lines, apply script -e = evaluate the following script print unless 1..10 Well... the '..' operator has been explained every other mail on this list :-| Basically, this one returns true if you're between lines 1 and 10 (inclusive), which means those lines won't get printed, but all others will. HTH, jac PS: If you'd like a more detailed explanation of the .. operator or something else, just say it :-) I'm just not explaining it because you've probably already read about it here... :-) for eg in sed I can do the same in two steps cat FILENAME | sed -e '1,10d' FILENAME.TMP mv FILENAME.TMP FILENAME The above mechanism has a lot of pitfalls , like maintaining permissions , making sure FILENAME.TMP does not already exist etc. That is why I want to do it with perl -i but I dont want to write a full script for this , because I am going to run it on remote machines ( automated ) , and I cant ftp the script everywhere Any suggestions Thanks Ram -- José Alves de Castro [EMAIL PROTECTED] http://natura.di.uminho.pt/~jac signature.asc Description: This is a digitally signed message part
Re: What is this doing: eval 'exec /usr/bin/perl -T -w -S $0 ${1+$@}' if 0;
On Sun, 2004-08-08 at 04:06, JupiterHost.Net wrote: I found this code in a script right after the she-bang line: eval 'exec /usr/bin/perl -T -w -S $0 ${1+$@}' if 0; # not running under some shell What is it doing? Hi. From `perldoc perlrun`, under -S : Typically this is used to emulate #! startup on platforms that don't support #!. This example works on many platforms that have a shell compatible with Bourne shell: #!/usr/bin/perl eval 'exec /usr/bin/perl -wS $0 ${1+$@}' if $running_under_some_shell; [ ... etc ... ] It goes on, so you have a more detailed explanation there... The line you have is similar enough to that one. Its like its executing itself again, but why? What the heck is: ${1+$@} ?? Wouldn't the eval never get done because of the if 0; ?? Right. Probably your system supports #!, right? :-) So why eval a piece of code that willnever be eval'ed ? I guess the line is still there for some reason... I can think of several possibilities :-| Thanks! Lee.M - JupiterHost.Net -- José Alves de Castro [EMAIL PROTECTED] http://natura.di.uminho.pt/~jac signature.asc Description: This is a digitally signed message part
Re: What is this doing: eval 'exec /usr/bin/perl -T -w -S $0 ${1+$@}' if 0;
Jose Alves de Castro wrote: On Sun, 2004-08-08 at 04:06, JupiterHost.Net wrote: I found this code in a script right after the she-bang line: eval 'exec /usr/bin/perl -T -w -S $0 ${1+$@}' if 0; # not running under some shell What is it doing? Hi. From `perldoc perlrun`, under -S : Hello Jose, Right on, you'd think I'd check perldoc first, every now and then I get dumb ;p Thanks! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
File Size Calculator
Hi all, I'm trying to writing a script that will allow a user to enter a number and that number will be converted into KB,MB or GB depending on the size of the number. Can someone point me in the right direction? Example: user enter: 59443 Script will output: 58M SilverFox -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: File Size Calculator
On 9 Aug 2004, at 14:34, SilverFox wrote: Hi all, I'm trying to writing a script that will allow a user to enter a number and that number will be converted into KB,MB or GB depending on the size of the number. Can someone point me in the right direction? What have you got so far? Where are you stuck? Getting user input (where from)? Working out which order of magnitude the number is? Converting between kilo and mega et al? Showing the output? Show us some code. -- David Dorward http://dorward.me.uk/ http://blog.dorward.me.uk/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Trying To write a script
I am trying to write a script that would be able to read a file. The file is broken into number of segments and each segment starts with a similar string pattern of following type: 2.2.x.y.z: followed with white space, where x, y, z numbers change throughout the file. The segment further has number of things that I am looking for. I want to be able to capture the segment value in addition to other things in a specific segment. What is the best approach to be able to make this possible? I have tried number of things but have not been able to capture the right regular expression to capture the information. I would appreciate if any one can send in their response... Regards, Harjit Singh
Re: File Size Calculator
On Mon, 2004-08-09 at 14:53, David Dorward wrote: On 9 Aug 2004, at 14:34, SilverFox wrote: Hi all, I'm trying to writing a script that will allow a user to enter a number and that number will be converted into KB,MB or GB depending on the size of the number. Can someone point me in the right direction? What have you got so far? Where are you stuck? Getting user input (where from)? Working out which order of magnitude the number is? I wouldn't do that (the part of finding the order of magnitude)... I would probably keep on doing calculations while the numbers was greater then 1024... and in the end, when it was, the right letter to append would be based on the amount of calculations done... I remember reading something about this on use.Perl ... it was a while ago, and I'm not sure whether it ever got into a module, but the guy had written some wonderful code to do this :-) Converting between kilo and mega et al? Showing the output? Show us some code. -- David Dorward http://dorward.me.uk/ http://blog.dorward.me.uk/ -- José Alves de Castro [EMAIL PROTECTED] http://natura.di.uminho.pt/~jac signature.asc Description: This is a digitally signed message part
Re: Trying To write a script
On Aug 9, 2004, at 9:05 AM, Singh, Harjit wrote: I am trying to write a script that would be able to read a file. The file is broken into number of segments and each segment starts with a similar string pattern of following type: 2.2.x.y.z: followed with white space, where x, y, z numbers change throughout the file. The segment further has number of things that I am looking for. I want to be able to capture the segment value in addition to other things in a specific segment. What is the best approach to be able to make this possible? I have tried number of things but have not been able to capture the right regular expression to capture the information. I would appreciate if any one can send in their response... Show us a few lines of data, please, and the expressions you have tried. We'll walk you through why they aren't working and give some pointers. James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Trying To write a script
Harjit Singh wrote: I am trying to write a script that would be able to read a file. Are you? I don't see any code. verbal file description snipped What is the best approach to be able to make this possible? I have no idea. But the best approach when seeking help here is to post a small but complete program, including sample data, that people can easily copy and run, and that illustrates the problem you are encountering. -- 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/ http://learn.perl.org/first-response
RE: Trying To write a script
-Original Message- From: Singh, Harjit [mailto:[EMAIL PROTECTED] Sent: Monday, August 09, 2004 4:05 PM To: [EMAIL PROTECTED] Subject: Trying To write a script I am trying to write a script that would be able to read a file. The file is broken into number of segments and each segment starts with a similar string pattern of following type: 2.2.x.y.z: followed with white space, where x, y, z numbers change throughout the file. The segment further has number of things that I am looking for. I want to be able to capture the segment value in addition to other things in a specific segment. What is the best approach to be able to make this possible? I have tried number of things but have not been able to capture the right regular expression to capture the information. I would appreciate if any one can send in their response... Regards, Harjit Singh Can you send a file example. Don't considering the file size. use Data::Dumper; my @file = split(/(2\.2\./d+\./d+\./d+) /, $fileText); shift(@file); my %blocks = @file; print(Dumper(\%blocks)); In blocks you would find the keys read to be parsed and the values as being the rest. One real example cloud help. Marcos -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: File Size Calculator
On Mon, 9 Aug 2004, SilverFox wrote: Example: user enter: 59443 Script will output: 58M I know this isn't getting into the spirit of things, but have you considered simply using the `units` program? % units 500 units, 54 prefixes You have: 59443 bytes You want: megabytes * 0.056689262 / 17.640025 You have: 59443 bytes You want: kilobytes * 59.443 / 0.016822839 You have: ^C % units bytes kilobytes * 0.001 / 1000 % units bytes megabytes * 9.5367432e-07 / 1048576 The nice thing about `units` -- in this context -- is that it lets the user pick the conversion units they want to work with, and also gives hints for converting both to from the alternate measurement scale. Of course, working this into a larger program that does other things might be annoying -- in which case your way is better -- but if all you want is the conversions, this is a solved problem :-) -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: COMPLEX ARRAY STRUCTURE
yes, I'm pretty sure. And Ramprasad is write, it's a LDAP-Perl scructure. I need to construct this structure on fly when executin a script. So I wish first how to access. So, lets tell I want to add another element. After doing: my %hash = @{$a}; I do: $hash{'initials'} = S; ??? If I heed an array shoul I do: $hash{'telephone'}=['','']; and because it's a anonymous reference $a var is update automatly? Merci beacoupe LD El Lun 09 Ago 2004 03:32, Tim Johnson escribió: Are you sure you want that top level to be an anonymous array instead of a hash? This would make more sense (see below for how to access the values). Note the {} brackets instead of the [] brackets. # my $a = {'cn' = ['Barbara Jensen', 'Barbs Jensen'], 'sn' = 'Jensen', 'mail' = '[EMAIL PROTECTED]', 'objectclass' = ['top', 'person', 'organizationalPerson', 'inetOrgPerson' ], }; print $a-{objectclass}-[3].\n; #inetOrgPerson print $a-{sn}.\n; #Jensen # -Original Message- From: Luis Daniel Lucio Quiroz [mailto:[EMAIL PROTECTED] Sent: Sunday, August 08, 2004 5:50 PM To: [EMAIL PROTECTED] Subject: COMPLEX ARRAY STRUCTURE Hi, $a = [ 'cn' = ['Barbara Jensen', 'Barbs Jensen'], 'sn' = 'Jensen', 'mail' = '[EMAIL PROTECTED]', 'objectclass' = ['top', 'person', 'organizationalPerson', 'inetOrgPerson' ], ]; I have this arrary structure, how should I read it? For example how do I acces to inetOrgPerson' value or Jesen value? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: question
well yes I thought I tried that, but maybe I type something wrong b/c I am not seeing what I remember. Yours works! thanks! Derek B. Smith OhioHealth IT UNIX / TSM / EDM Teams 614-566-4145 Gunnar Hjalmarsson [EMAIL PROTECTED] 08/04/2004 06:12 PM To: [EMAIL PROTECTED] cc: Subject:Re: question [EMAIL PROTECTED] wrote: Is the last unless statement saying break out of the loop only when @a is read completely through? In effect: Yes. I also have a formatting question. The output is printing a ' after a newline A wild guess would be that it's because the ' is printed after the printing of a \n. ;-) Have you tried: print join ($or_string, @output), $tick, \n; -- 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/ http://learn.perl.org/first-response
Re: COMPLEX ARRAY STRUCTURE
On Mon, 9 Aug 2004, Luis Daniel Lucio Quiroz wrote: And Ramprasad is write, it's a LDAP-Perl scructure. I need to construct this structure on fly when executin a script. So I wish first how to access. So, lets tell I want to add another element. After doing: my %hash = @{$a}; Did you try a `perldoc Net::LDAP` yet? SYNOPSIS use Net::LDAP; $ldap = Net::LDAP-new( 'ldap.bigfoot.com' ) or die $@; $mesg = $ldap-bind ;# an anonymous bind $mesg = $ldap-search( # perform a search base = c=US, filter = ((sn=Barr) (o=Texas Instruments)) ); $mesg-code die $mesg-error; foreach $entry ($mesg-entries) { $entry-dump; } $mesg = $ldap-unbind; # take down session $ldap = Net::LDAP-new( 'ldap.umich.edu' ); # bind to a directory with dn and password $mesg = $ldap-bind( 'cn=root, o=University of Michigan, c=us', password = 'secret' ); $result = $ldap-add( 'cn=Barbara Jensen, o=University of Michigan, c=US', attr = [ 'cn' = ['Barbara Jensen', 'Barbs Jensen'], 'sn' = 'Jensen', 'mail' = '[EMAIL PROTECTED]', 'objectclass' = ['top', 'person', 'organizationalPerson', 'inetOrgPerson' ], ] ); $result-code warn failed to add entry: , $result-error ; $mesg = $ldap-unbind; # take down session Can you not add an entry this way? -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: COMPLEX ARRAY STRUCTURE
Yes I do, I need array not to be hard-coded El Lun 09 Ago 2004 10:05, Chris Devers escribió: On Mon, 9 Aug 2004, Luis Daniel Lucio Quiroz wrote: And Ramprasad is write, it's a LDAP-Perl scructure. I need to construct this structure on fly when executin a script. So I wish first how to access. So, lets tell I want to add another element. After doing: my %hash = @{$a}; Did you try a `perldoc Net::LDAP` yet? SYNOPSIS use Net::LDAP; $ldap = Net::LDAP-new( 'ldap.bigfoot.com' ) or die $@; $mesg = $ldap-bind ;# an anonymous bind $mesg = $ldap-search( # perform a search base = c=US, filter = ((sn=Barr) (o=Texas Instruments)) ); $mesg-code die $mesg-error; foreach $entry ($mesg-entries) { $entry-dump; } $mesg = $ldap-unbind; # take down session $ldap = Net::LDAP-new( 'ldap.umich.edu' ); # bind to a directory with dn and password $mesg = $ldap-bind( 'cn=root, o=University of Michigan, c=us', password = 'secret' ); $result = $ldap-add( 'cn=Barbara Jensen, o=University of Michigan, c=US', attr = [ 'cn' = ['Barbara Jensen', 'Barbs Jensen'], 'sn' = 'Jensen', 'mail' = '[EMAIL PROTECTED]', 'objectclass' = ['top', 'person', 'organizationalPerson', 'inetOrgPerson' ], ] ); $result-code warn failed to add entry: , $result-error ; $mesg = $ldap-unbind; # take down session Can you not add an entry this way? -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Assignment for Perl Class- hurting my brain
(Let's keep our discussion on the list, for all to help and learn.) On Aug 8, 2004, at 11:08 PM, William Paoli wrote: The field format of the file is structured like this: Car Number:Driver Name:Sponsor:Owner:Crew Chief:Car Make:Mini Biography:Team Name I couldn't tell, are you struggling with this part? Yes actually I think I am. Am I on the right track with: sub load_data_file { open FILE, winstoncup_2002_drivers.txt; @driver_info = FILE; This slurps the entire file into the array. I assume that would be a lot of drivers. Don't you just want to walk through them one at a time? A typical line-by-line read in Perl looks something like: while (my $line = FILE) { # work with $line here... } while (@driver_info) { That says, While there are elements in the array driver_info... You aren't removing any elements below though, meaning it will always be true and thus probably an infinite loop. Again, I think you meant to deal with the file line-by-line. $obj = $Car_Number, $Driver_Name,$Sponsor,$Owner,$Chief,$Car,$Bio,$Team = split /:/; split /:/ is just short for split /:/, $_, but I don't see you setting $_ anywhere. I doubt that's doing what you expect. The assignment is another issue. I don't know what you're trying with $obj =, but I doubt you're getting what you expect there. As for the rest, use parens around your lists, so you can see they are lists: ($list, $of, $some, @vars) = split ... ; Hopefully that gives you some new things to think about. James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Assignment for Perl Class- hurting my brain
William Paoli wrote: $obj = {Title} =; #Is this initilizing the attribute? I dont know why I am just not getting this stuff. Please help me. your syntax is wrong, thats all. so your assignment is make some kinda rudimentary database lookup program thingie? your program reads the file, then accepts some kind of input to lookup info that was in the file? honestly, i don't really know what the prof wants with this attributes thing. it seems to kinda confuse things for no reason, but whatever. sub new { my $self = {}; $self-{TITLE} = 'whatever title'; bless( $self ); return $self; } i don't know the specs for your project, but my constructor would probably look like this: sub new { my ($caller, $filename) = @_; my $class = ref($caller) || $caller; my $self = {}; bless($self, $class); $self-{TITLE} = 'My Title!'; $self-{FILENAME} = $filename; parse_file($filename); # dunno, this might be $self-parse_file($filename) return $self; } its kinda hard to help without knowing exactly how much you know about perl... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: COMPLEX ARRAY STRUCTURE
On Mon, 9 Aug 2004, Luis Daniel Lucio Quiroz wrote: Yes I do, I need array not to be hard-coded So don't hard-code it then. Just modify the update command the library provides so that it does what you need it to do. Manually poking at the data structure that a library uses internally is a BAD idea; it breaks the whole point of using object-oriented methods. So. You want to change how you do an update. So take this -- $result = $ldap-add( 'cn=Barbara Jensen, o=University of Michigan, c=US', attr = [ 'cn' = ['Barbara Jensen', 'Barbs Jensen'], 'sn' = 'Jensen', 'mail' = '[EMAIL PROTECTED]', 'objectclass' = ['top', 'person', 'organizationalPerson', 'inetOrgPerson' ], ] ); $result-code warn failed to add entry: , $result-error ; And edit the fields you need to have added. $result = $ldap-add( 'cn' = ['George Kaplan', 'Roger Thornhill'], 'mail' = '[EMAIL PROTECTED]' ); $result-code warn failed to add entry: , $result-error; $result = $ldap-add( 'cn' = [$name, $nick], 'mail' = $mail ); $result-code warn failed to add $name/$mail: , $result-error; In what way isn't this working for you? If you try to poke at the data structure Net::LDAP is using without going through the $ldap-add() method provided, you're probably going to regret it in the long run, when -- as inevitably happens -- some random update changes how things are stored but not the API and your code that depended on the old storage mechanism falls apart with the new one. If on the other hand you just use the normal API, you should be safe. -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: iterate over the fields of a struct?
Randy W. Sims wrote: If you're using version 5.8 or later you can use restricted hashes. See `perldoc Hash::Util` heh, that was exactly what i'm looking for, thanks. ugh, now i gotta rewrite 3 days worth of code with restricted hashes instead of Class::Struct ...=/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: COMPLEX ARRAY STRUCTURE
You are wrong, I need some more flexible, I dont know what attributes will be added, that's why I need array be coded on fly,with somthin like this $result = $ldap-add( 'cn=Barbara Jensen, o=University of Michigan, c=US', attr =$attrs); so $attrs array is formed on user commands :-P LD El Lun 09 Ago 2004 10:35, Chris Devers escribió: On Mon, 9 Aug 2004, Luis Daniel Lucio Quiroz wrote: Yes I do, I need array not to be hard-coded So don't hard-code it then. Just modify the update command the library provides so that it does what you need it to do. Manually poking at the data structure that a library uses internally is a BAD idea; it breaks the whole point of using object-oriented methods. So. You want to change how you do an update. So take this -- $result = $ldap-add( 'cn=Barbara Jensen, o=University of Michigan, c=US', attr = [ 'cn' = ['Barbara Jensen', 'Barbs Jensen'], 'sn' = 'Jensen', 'mail' = '[EMAIL PROTECTED]', 'objectclass' = ['top', 'person', 'organizationalPerson', 'inetOrgPerson' ], ] ); $result-code warn failed to add entry: , $result-error ; And edit the fields you need to have added. $result = $ldap-add( 'cn' = ['George Kaplan', 'Roger Thornhill'], 'mail' = '[EMAIL PROTECTED]' ); $result-code warn failed to add entry: , $result-error; $result = $ldap-add( 'cn' = [$name, $nick], 'mail' = $mail ); $result-code warn failed to add $name/$mail: , $result-error; In what way isn't this working for you? If you try to poke at the data structure Net::LDAP is using without going through the $ldap-add() method provided, you're probably going to regret it in the long run, when -- as inevitably happens -- some random update changes how things are stored but not the API and your code that depended on the old storage mechanism falls apart with the new one. If on the other hand you just use the normal API, you should be safe. -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
perl.beginners Weekly list FAQ posting
NAME beginners-faq - FAQ for the beginners mailing list 1 - Administriva 1.1 - I'm not subscribed - how do I subscribe? Send mail to [EMAIL PROTECTED] You can also specify your subscription email address by sending email to (assuming [EMAIL PROTECTED] is your email address): [EMAIL PROTECTED]. 1.2 - How do I unsubscribe? Now, why would you want to do that? Send mail to [EMAIL PROTECTED], and wait for a response. Once you reply to the response, you'll be unsubscribed. If that doesn't work, find the email address which you are subscribed from and send an email like the following (let's assume your email is [EMAIL PROTECTED]): [EMAIL PROTECTED] 1.3 - There is too much traffic on this list. Is there a digest? Yes. To subscribe to the digest version of this list send an email to: [EMAIL PROTECTED] To unsubscribe from the digest, send an email to: [EMAIL PROTECTED] This is a high traffic list (100+ messages per day), so please subscribe in the way which is best for you. 1.4 - Is there an archive on the web? Yes, there is. It is located at: http://archive.develooper.com/beginners%40perl.org/ 1.5 - How can I get this FAQ? This document will be emailed to the list once a week, and will be available online in the archives, and at http://learn.perl.org/ 1.6 - I don't see something in the FAQ, how can I make a suggestion? Send an email to [EMAIL PROTECTED] with your suggestion. 1.7 - Is there a supporting website for this list? Yes, there is. It is located at: http://beginners.perl.org/ 1.8 - Who do I complain to? You can send complaints to [EMAIL PROTECTED] 1.9 - Who currently maintains the FAQ? Kevin Meltzer, who can be reached at the email address (for FAQ suggestions only) in question 1.6 1.10 - Who will maintain peace and flow on the list? Casey West, Kevin Meltzer and Ask Bjoern Hansen currently carry large, yet padded, clue-sticks to maintain peace and order on the list. If you are privately emailed by one of these folks for flaming, being off-topic, etc... please listen to what they say. If you see a message sent to the list by one of these people saying that a thread is closed, do not continue to post to the list on that thread! If you do, you will not only meet face to face with a XQJ-37 nuclear powered pansexual roto-plooker, but you may also be taken off of the list. These people simply want to make sure the list stays topical, and above-all, useful to Perl beginners. 1.11 - When was this FAQ last updated? Feb 04, 2004 2 - Questions about the 'beginners' list. 2.1 - What is the list for? A list for beginning Perl programmers to ask questions in a friendly atmosphere. 2.2 - What is this list _not_ for? * SPAM * Homework * Solicitation * Things that aren't Perl related * Monkeys * Monkeys solicitating homework on non-Perl related SPAM. 2.3 - Are there any rules? Yes. As with most communities, there are rules. Not many, and ones that shouldn't need to be mentioned, but they are. * Be nice * No flaming * Have fun 2.4 - What topics are allowed on this list? Basically, if it has to do with Perl, then it is allowed. You can ask CGI, networking, syntax, style, etc... types of questions. If your question has nothing at all to do with Perl, it will likely be ignored. If it has anything to do with Perl, it will likely be answered. 2.5 - I want to help, what should I do? Subscribe to the list! If you see a question which you can give an idiomatic and Good answer to, answer away! If you do not know the answer, wait for someone to answer, and learn a little. 2.6 - Is there anything I should keep in mind while answering? We don't want to see 'RTFM'. That isn't very helpful. Instead, guide the beginner to the place in the FM they should R :) Please do not quote the documentation unless you have something to add to it. It is better to direct someone to the documentation so they hopefully will read documentation above and beyond that which answers their question. It also helps teach them how to use the documentation. 2.7 - I don't want to post a question if it is in an FAQ. Where should I look first? Look in the FAQ! Get acquainted with the 'perldoc' utility, and use it. It can save everyone time if you look in the Perl FAQs first, instead of having a list of people refer you to the Perl FAQs :) You can learn about 'perldoc' by typing: perldoc perldoc At your command prompt. You can also view documentation online at: http://www.perldoc.com and http://www.perl.com 2.8 Is this a high traffic list? YES! You have been warned! If you don't want to get ~100 emails per day from this list, consider subscribing to the digest. 2.9 Other tips before posting to the list
Re: COMPLEX ARRAY STRUCTURE
On Mon, 9 Aug 2004, Luis Daniel Lucio Quiroz wrote: You are wrong, I see. Good luck figuring it out then! -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
regex problem
All I am getting the error from my if statement: ^* matches null string many times in regex; marked by -- HERE in m/^* -- HERE Orig/ at . I am trying to get everything except *Orig in this output : *Orig Vol: 1703FBBDED58D4AD (E00117), Seq #: 000114 in TLU: st_9840_acs_0, media: STK 984e Orig Vol: 0303E68522777483 (E00486), Seq #: 000800 in TLU: st_9840_acs_0, media: STK 984e 07/12/2004 18:13:17 Rotation ID:4A03CC27.A30DEE72.0200.0E0B8707, 5 backups Media duplication is not enabled. *Orig Vol: 4A03CC27A30DEE72 (E00632), Seq #: 000273 in TLU: st_9840_acs_0, media: STK 984e Here is my code: foreach ($EDM_nonactive_tapelist) { if ($EDM_nonactive_tapelist !~ \^\*Orig) { print $_; } } *NOTE the variable $EDM_nonactive_tapelist has the Orig strings in it. Does foreach read line by line? Do I even need the foreach statement? thank you! Derek B. Smith OhioHealth IT UNIX / TSM / EDM Teams
RE: Trying To write a script
The following code is what I used to check if item number could be detected for the file I sent in the earlier email. The code seems to have failed and need a advise on it.. #!C:\perl\bin\perl5.6.1 $file1 = ' C:\perl\bin\dummy.txt' ; open (INFO, $file1 ) or die Can't open $file: $1; while (INFO) { if ($test = ~ /2\.2\./d+\./d+\./d+){ print $test \n ; }} close (INFO); It would be a great help if some feedback could be provided... Sunny.. -Original Message- From: Singh, Harjit Sent: Monday, August 09, 2004 12:23 PM To: 'Gunnar Hjalmarsson' Subject: RE: Trying To write a script Gunnar, The file is of the following format: --- 2.2.4.3.4 XXX This is test of test for use by Sunny: 1 as stated in 2.2.5.6.1 2.2.5.6.9 YY Note 2: This function consolidates a number of former sections from 3.2.4. for use by Sunny: 2 as discussed in 2.1.2.1 -- The file shows two items start with 2.2.* and additional detail underneath it such as Sunny: 1 for 2.2.4.3.4 or Sunny: 2 for 2.2.5.6.9. I want to be able to break the file capturing its item number along with number for Sunny: for each of the listed item number. The item number always starts in the beginning of line. See if this helps you in deciding a code. Regards, Sunny -Original Message- From: Gunnar Hjalmarsson [mailto:[EMAIL PROTECTED] Sent: Monday, August 09, 2004 10:12 AM To: [EMAIL PROTECTED] Subject: Re: Trying To write a script Harjit Singh wrote: I am trying to write a script that would be able to read a file. Are you? I don't see any code. verbal file description snipped What is the best approach to be able to make this possible? I have no idea. But the best approach when seeking help here is to post a small but complete program, including sample data, that people can easily copy and run, and that illustrates the problem you are encountering. -- 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/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Trying To write a script
On Aug 9, 2004, at 3:36 PM, Singh, Harjit wrote: The following code is what I used to check if item number could be detected for the file I sent in the earlier email. The code seems to have failed and need a advise on it.. #!C:\perl\bin\perl5.6.1 $file1 = ' C:\perl\bin\dummy.txt' ; open (INFO, $file1 ) or die Can't open $file: $1; while (INFO) { if ($test = ~ /2\.2\./d+\./d+\./d+){ In a Regular Expression, one or more digits is spelled: \d+ Hope that helps. James print $test \n ; }} close (INFO); It would be a great help if some feedback could be provided... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: regex problem
[EMAIL PROTECTED] wrote: All I am getting the error from my if statement: ^* matches null string many times in regex; marked by -- HERE in m/^* -- HERE Orig/ at . I am trying to get everything except *Orig in this output : samlpe data snipped Here is my code: foreach ($EDM_nonactive_tapelist) { if ($EDM_nonactive_tapelist !~ \^\*Orig) { print $_; } } - The ^ character shall not be escaped when marking the beginning of a string. - You need to tell Perl that you want to use the m// operator, either like m^\*Orig or by using straight slashes: /^\*Orig/ But why use a regex at all? print unless substr($_, 0, 5) eq '*Orig'; *NOTE the variable $EDM_nonactive_tapelist has the Orig strings in it. Does foreach read line by line? Not unless you tell Perl so: foreach ( split /\n/, $EDM_nonactive_tapelist ) { print $_\n unless substr($_, 0, 5) eq '*Orig'; } Do I even need the foreach statement? No. print map $_\n, grep { substr($_, 0, 5) ne '*Orig' } $EDM_nonactive_tapelist =~ /(.+)/mg; ;-) -- 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/ http://learn.perl.org/first-response
Re: regex problem
I am still getting the same error with your suggestion. Does foreach read line by line? Do I need the foreach? Derek B. Smith OhioHealth IT UNIX / TSM / EDM Teams 614-566-4145 Felix Li [EMAIL PROTECTED] 08/09/2004 03:56 PM To: [EMAIL PROTECTED] cc: Subject:Re: regex problem perhaps you meant ^\* ... rather than \^\* ... the later will trap things beginning with ^* ... - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, August 09, 2004 3:54 PM Subject: regex problem All I am getting the error from my if statement: ^* matches null string many times in regex; marked by -- HERE in m/^* -- HERE Orig/ at . I am trying to get everything except *Orig in this output : *Orig Vol: 1703FBBDED58D4AD (E00117), Seq #: 000114 in TLU: st_9840_acs_0, media: STK 984e Orig Vol: 0303E68522777483 (E00486), Seq #: 000800 in TLU: st_9840_acs_0, media: STK 984e 07/12/2004 18:13:17 Rotation ID:4A03CC27.A30DEE72.0200.0E0B8707, 5 backups Media duplication is not enabled. *Orig Vol: 4A03CC27A30DEE72 (E00632), Seq #: 000273 in TLU: st_9840_acs_0, media: STK 984e Here is my code: foreach ($EDM_nonactive_tapelist) { if ($EDM_nonactive_tapelist !~ \^\*Orig) { print $_; } } *NOTE the variable $EDM_nonactive_tapelist has the Orig strings in it. Does foreach read line by line? Do I even need the foreach statement? thank you! Derek B. Smith OhioHealth IT UNIX / TSM / EDM Teams
RE: Trying To write a script
James, I made the change but still did not fix my problem.. Sunny. -Original Message- From: James Edward Gray II [mailto:[EMAIL PROTECTED] Sent: Monday, August 09, 2004 4:41 PM To: Singh, Harjit Cc: Perl Beginners Subject: Re: Trying To write a script On Aug 9, 2004, at 3:36 PM, Singh, Harjit wrote: The following code is what I used to check if item number could be detected for the file I sent in the earlier email. The code seems to have failed and need a advise on it.. #!C:\perl\bin\perl5.6.1 $file1 = ' C:\perl\bin\dummy.txt' ; open (INFO, $file1 ) or die Can't open $file: $1; while (INFO) { if ($test = ~ /2\.2\./d+\./d+\./d+){ In a Regular Expression, one or more digits is spelled: \d+ Hope that helps. James print $test \n ; }} close (INFO); It would be a great help if some feedback could be provided... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Trying To write a script
Singh, Harjit wrote: The following code is what I used to check if item number could be detected for the file I sent in the earlier email. The code seems to have failed and need a advise on it.. A couple of suggestions/corrections: #!C:\perl\bin\perl5.6.1 use strict; use warnings; $file1 = ' C:\perl\bin\dummy.txt' ; open (INFO, $file1 ) or die Can't open $file: $1; while (INFO) This assigns each line in turn to the special variable $_ { if ($test = ~ /2\.2\./d+\./d+\./d+){ so, matching against $test, which is undefined, does nothing. Also, the regular expression should not be in quotes. What you want to do is match the regular expression againg $_ and capture the data you want using the regular expression capture operator (). Using your above expression that would be something like: if ( $_ =~ /2\.2\.(/d+)\.(/d+)\.(/d+)/ ){ or since the $_ variable is implied, it can be shortened to: if ( /2\.2\.(/d+)\.(/d+)\.(/d+)/ ){ print $test \n ; }} Using the above captures, your results will now be in the variables $1, $2, $3. close (INFO); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Trying To write a script
Randy, The code is still not working with the modifications that you listed earlier. The code does not have any compilation errors but does not show the results for the variables $1, $2 and $3. I was wandering if you could think of something else that is causing the problem. #!C:\perl\bin\perl5.6.1 $file1 = ' C:\perl\bin\dummy.txt' ; open (INFO, $file1 ) or die Can't open $file: $1; while (INFO) { if (/2\.2\.(\d+)\.(\d+)\.(\d+)/) { print $1,$2, $3 ; }} close (INFO); Thanks, Sunny.. -Original Message- From: Randy W. Sims [mailto:[EMAIL PROTECTED] Sent: Monday, August 09, 2004 4:57 PM To: Singh, Harjit Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: Trying To write a script Singh, Harjit wrote: The following code is what I used to check if item number could be detected for the file I sent in the earlier email. The code seems to have failed and need a advise on it.. A couple of suggestions/corrections: #!C:\perl\bin\perl5.6.1 use strict; use warnings; $file1 = ' C:\perl\bin\dummy.txt' ; open (INFO, $file1 ) or die Can't open $file: $1; while (INFO) This assigns each line in turn to the special variable $_ { if ($test = ~ /2\.2\./d+\./d+\./d+){ so, matching against $test, which is undefined, does nothing. Also, the regular expression should not be in quotes. What you want to do is match the regular expression againg $_ and capture the data you want using the regular expression capture operator (). Using your above expression that would be something like: if ( $_ =~ /2\.2\.(/d+)\.(/d+)\.(/d+)/ ){ or since the $_ variable is implied, it can be shortened to: if ( /2\.2\.(/d+)\.(/d+)\.(/d+)/ ){ print $test \n ; }} Using the above captures, your results will now be in the variables $1, $2, $3. close (INFO); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Trying To write a script
Singh, Harjit wrote: Randy, The code is still not working with the modifications that you listed earlier. The code does not have any compilation errors but does not show the results for the variables $1, $2 and $3. I was wandering if you could think of something else that is causing the problem. #!C:\perl\bin\perl5.6.1 You forgot: use strict; use warnings; $file1 = ' C:\perl\bin\dummy.txt' ; my $file1 = ' C:\perl\bin\dummy.txt' ; open (INFO, $file1 ) or die Can't open $file: $1; ^^ Your die message uses a different variable ($file vs $file1). And you probably meant $! vs $1 to display the error message. open (INFO, $file1 ) or die Can't open $file1: $!; while (INFO) { if (/2\.2\.(\d+)\.(\d+)\.(\d+)/) { print $1,$2, $3 ; }} close (INFO); Despite the problems mentioned above, I'm not sure why it didn't work for you. Your code works as is for me with a dummy.txt file of, eg. 2.2.100.200.300 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: regex problem
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: : All I am getting the error from my if statement: : : ^* matches null string many times in regex; marked by -- : HERE in m/^* -- : HERE Orig/ at . : : I am trying to get everything except *Orig in this output : : : *Orig Vol: 1703FBBDED58D4AD (E00117), Seq #: 000114 in TLU: : st_9840_acs_0, media: STK 984e : Orig Vol: 0303E68522777483 (E00486), Seq #: 000800 in TLU: : st_9840_acs_0, media: STK 984e : : 07/12/2004 18:13:17 Rotation : ID:4A03CC27.A30DEE72.0200.0E0B8707, 5 : backups : Media duplication is not enabled. : : *Orig Vol: 4A03CC27A30DEE72 (E00632), Seq #: 000273 in TLU: : st_9840_acs_0, media: STK 984e : : Here is my code: : : foreach ($EDM_nonactive_tapelist) { : if ($EDM_nonactive_tapelist !~ \^\*Orig) { : print $_; : } : } : : *NOTE the variable $EDM_nonactive_tapelist has the Orig strings : in it. Does foreach read line by line? No. 'foreach' as used above aliases $_ to each element of a list of scalars one item at a time. The function does not know the concept of line. You have provided a list of one scalar - $EDM_nonactive_tapelist. The loop will process $EDM_nonactive_tapelist once and place it's value in $_. Any changes to $_ will also change $EDM_nonactive_tapelist. Assuming $EDM_nonactive_tapelist has a list of strings separated by newlines (\n), a list of those strings might be expressed as this. foreach my $srting ( split /\n/, $EDM_nonactive_tapelist ) { print $srting\n if /^\*Orig/; } In this example we have taken each string and placed it in a scalar variable named $string. $string is tested and printed if that test is true. The 'split' splits each string at the newline and discard that character. : Do I even need the foreach statement? I'm not sure. has the Orig strings in it is not a precise statement for a computer programmer. Question: How did this list of strings get into a single scalar? HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Trying To write a script
Randy, I tried the following code as you mentioned but still seem to be failing to do any print on the screen. The code is as follows: use strict; use warnings; # $file1 = ' C:\perl\bin\dummy.txt' ; my $file1 = ' C:\perl\bin\dummy.txt' ; #Your die message uses a different variable ($file vs $file1). And you # probably meant $! vs $1 to display the error message. open (INFO, $file1 ) or die Can't open $file1: $!; while (INFO) { if (/2\.2\.(\d+)\.(\d+)\.(\d+)/) { print $1,$2, $3 ; }} close (INFO); Regards, SUnny -Original Message- From: Randy W. Sims [mailto:[EMAIL PROTECTED] Sent: Monday, August 09, 2004 5:27 PM To: Singh, Harjit Cc: [EMAIL PROTECTED] Subject: Re: Trying To write a script Singh, Harjit wrote: Randy, The code is still not working with the modifications that you listed earlier. The code does not have any compilation errors but does not show the results for the variables $1, $2 and $3. I was wandering if you could think of something else that is causing the problem. #!C:\perl\bin\perl5.6.1 You forgot: use strict; use warnings; $file1 = ' C:\perl\bin\dummy.txt' ; my $file1 = ' C:\perl\bin\dummy.txt' ; open (INFO, $file1 ) or die Can't open $file: $1; ^^ Your die message uses a different variable ($file vs $file1). And you probably meant $! vs $1 to display the error message. open (INFO, $file1 ) or die Can't open $file1: $!; while (INFO) { if (/2\.2\.(\d+)\.(\d+)\.(\d+)/) { print $1,$2, $3 ; }} close (INFO); Despite the problems mentioned above, I'm not sure why it didn't work for you. Your code works as is for me with a dummy.txt file of, eg. 2.2.100.200.300 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: regex problem
it is a system app call that populates the $EDM_nonactive_tapelist I am not sure what you meanI'm not sure. has the Orig strings in it is not a precise statement for a computer programmer. the variable $EDM_nonactive_tapelist which is a file with the Orig strings in it ! the foreach with the split did work! thanks! Derek B. Smith OhioHealth IT UNIX / TSM / EDM Teams Charles K. Clarkson [EMAIL PROTECTED] 08/09/2004 05:41 PM To: [EMAIL PROTECTED], [EMAIL PROTECTED] cc: Subject:RE: regex problem [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: : All I am getting the error from my if statement: : : ^* matches null string many times in regex; marked by -- : HERE in m/^* -- : HERE Orig/ at . : : I am trying to get everything except *Orig in this output : : : *Orig Vol: 1703FBBDED58D4AD (E00117), Seq #: 000114 in TLU: : st_9840_acs_0, media: STK 984e : Orig Vol: 0303E68522777483 (E00486), Seq #: 000800 in TLU: : st_9840_acs_0, media: STK 984e : : 07/12/2004 18:13:17 Rotation : ID:4A03CC27.A30DEE72.0200.0E0B8707, 5 : backups : Media duplication is not enabled. : : *Orig Vol: 4A03CC27A30DEE72 (E00632), Seq #: 000273 in TLU: : st_9840_acs_0, media: STK 984e : : Here is my code: : : foreach ($EDM_nonactive_tapelist) { : if ($EDM_nonactive_tapelist !~ \^\*Orig) { : print $_; : } : } : : *NOTE the variable $EDM_nonactive_tapelist has the Orig strings : in it. Does foreach read line by line? No. 'foreach' as used above aliases $_ to each element of a list of scalars one item at a time. The function does not know the concept of line. You have provided a list of one scalar - $EDM_nonactive_tapelist. The loop will process $EDM_nonactive_tapelist once and place it's value in $_. Any changes to $_ will also change $EDM_nonactive_tapelist. Assuming $EDM_nonactive_tapelist has a list of strings separated by newlines (\n), a list of those strings might be expressed as this. foreach my $srting ( split /\n/, $EDM_nonactive_tapelist ) { print $srting\n if /^\*Orig/; } In this example we have taken each string and placed it in a scalar variable named $string. $string is tested and printed if that test is true. The 'split' splits each string at the newline and discard that character. : Do I even need the foreach statement? I'm not sure. has the Orig strings in it is not a precise statement for a computer programmer. Question: How did this list of strings get into a single scalar? HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328
Re: Trying To write a script
Harjit Singh wrote: The following code is what I used to check if item number could be detected for the file I sent in the earlier email. Did you send email to my [EMAIL PROTECTED] address? If the message in the user part of the address isn't sufficient, I can tell you that I never received your message. ;-) The code seems to have failed and need a advise on it.. #!C:\perl\bin\perl5.6.1 Where is use strict; use warnings; ?? $file1 = ' C:\perl\bin\dummy.txt' ; ^ ?? my $file1 = 'C:\perl\bin\dummy.txt'; open (INFO, $file1 ) or die Can't open $file: $1; while (INFO) I don't think it's a good approach to read the file line by line. I would slurp it into a scalar variable. $_ = do { local $/; INFO }; { if ($test = ~ /2\.2\./d+\./d+\./d+){ What on earth is that?? - When and how was $test populated? - The =~ operator does not include any space. - You haven't even learned the most basics about Perl regular expressions, have you? Please start studying perldoc perlrequick The file is of the following format: --- 2.2.4.3.4 XXX This is test of test for use by Sunny: 1 as stated in 2.2.5.6.1 2.2.5.6.9 YY Note 2: This function consolidates a number of former sections from 3.2.4. for use by Sunny: 2 as discussed in 2.1.2.1 -- The file shows two items start with 2.2.* and additional detail underneath it such as Sunny: 1 for 2.2.4.3.4 or Sunny: 2 for 2.2.5.6.9. I want to be able to break the file capturing its item number along with number for Sunny: for each of the listed item number. The item number always starts in the beginning of line. Assuming you have slurped the file into the $_ variable, you should be able to build a regex and do something like this: print Segment: $1 - Sunny: $2\n while /$re/g; But first you must of course learn how to write a regex... Besides the suggested docs above, you may want to check out the qr// operator in perldoc perlop. Good luck! -- 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/ http://learn.perl.org/first-response
RE: regex problem
[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: : it is a system app call that populates the : $EDM_nonactive_tapelist I am not sure what you mean : I'm not sure. has the Orig strings in it is not a : precise statement for a computer programmer. I meant that has the Orig strings in it does not tell us how the strings are represented. It does not precisely define how the data is structured. That statement does not accurately describe the data. Here are two examples of strings listed in a scalar. In both cases I could describe each of these examples as a scalar variable with strings in it. $baz = [ [ 'foo' ], [ 'bar' ], ]; $baz = foo\nbar\n; As computer programmers, we have to describe data precisely. If you are uncertain how to describe a structure try printing it with DATA::Dumper. : the foreach with the split did work! Great. I'm glad I could help. HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Net::FTP Help !
Hi Guys and Gals , I'm new to perl ... Here is my problem .. I'm connecting fine to the remote computer and logging in fine .. what I want to do is a get all files from the remote directory . Here is is a snippet of the code $ftp-cwd($remote_dir) or die cannot change working directory , $ftp-message; # show current directory $ftp-pwd(); @all_files = $ftp-ls(); print @all_files; foreach $file(@all_files) { $ftp-get($file) or die cannot get file, $ftp-message; } The problem is that the remote directory has a subdirectory in it so the array reads it in @all_files = $ftp-ls; so when I go to do a $ftp-get($file) it reads the subdirectory name into it as well so it bombs out saying it cannot find file BLAH BLAH ... is there a way to read the directory without the subdirectory in there .. just the files I want to get . Hope this is clear .. Thanks Chris - Visit our Internet site at http://www.reuters.com Get closer to the financial markets with Reuters Messaging - for more information and to register, visit http://www.reuters.com/messaging Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of Reuters Ltd.
Re: Net::FTP Help !
Hi Guys and Gals , I'm new to perl ... Here is my problem .. I'm connecting fine to the remote computer and logging in fine .. what I want to do is a get all files from the remote directory . Here is is a snippet of the code $ftp-cwd($remote_dir) or die cannot change working directory , $ftp-message; # show current directory $ftp-pwd(); @all_files = $ftp-ls(); print @all_files; foreach $file(@all_files) { $ftp-get($file) or die cannot get file, $ftp-message; } The problem is that the remote directory has a subdirectory in it so the array reads it in @all_files = $ftp-ls; so when I go to do a $ftp-get($file) it reads the subdirectory name into it as well so it bombs out saying it cannot find file BLAH BLAH ... is there a way to read the directory without the subdirectory in there .. just the files I want to get . Hope this is clear .. You can use the 'dir' method to get a long listing, which should include the permissions string. Then you can step through the list and pull only those files that don't start with a 'd'. This requires more parsing and is less precise but is the only way I know to do it. I thought someone was writing an extension that did this automatically but don't know if it has made its way to CPAN. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response