Form field named as array elements
Hi all, I need to present a series of database fields for users to update and when the form is submitted I need to be able to retrieve not only the field values but the original row ID's as well so I'll know which table rows to update. What I'd like to be able do is name the form fields as array elements: form input type=text name=question{'25'} value=$answer{'25'} input type=text name=question{'47'} value=$answer{'47'} /form Then when the form came back in, create update statements from the key/value pairs. while (($key,$value) = each %question) { $query = UPDATE tablename SET answer = '$value' WHERE id = '$key' ; } Does that make any sense at all? Can someone tell me how I'd do that in PERL? Thanks, Chuck Mayo
RE: Form field named as array elements
Works like a charm, thanks! Guess I was trying to make it to difficult. I must've done something wrong, though... I had to alter the code a bit to make it work. It seemed that grabbing all the params tossed the param values and I had to go back and get 'em once I had the key isolated. Naming the fields as you suggested: textarea name=question_41 rows=6 cols=60How's this gonna work?/textareabr textarea name=question_40 rows=6 cols=60Still another sample question/textareabr textarea name=question_44 rows=6 cols=60Here's a swell performance question!/textarea And scripting thusly: my $req = new CGI; my @URL_VARS = $req-param; foreach my $VARNAME (@URL_VARS) { if($VARNAME =~ /^question_(\d+)$/) { my $st = UPDATE tablename SET answer = ' . $req-param($VARNAME) . ' WHERE id = '$1'; print $st . br\n; } } Gave me: UPDATE tablename SET answer = 'How's this gonna work?' WHERE id = '41' UPDATE tablename SET answer = 'Still another sample question' WHERE id = '40' UPDATE tablename SET answer = 'Here's a swell performance question!' WHERE id = '44' -Original Message- From: Wiggins d Anconia [mailto:[EMAIL PROTECTED] Sent: Friday, November 14, 2003 2:19 PM To: Mayo, Chuck; '[EMAIL PROTECTED]' Subject: Re: Form field named as array elements Hi all, I need to present a series of database fields for users to update and when the form is submitted I need to be able to retrieve not only the field values but the original row ID's as well so I'll know which table rows to update. What I'd like to be able do is name the form fields as array elements: form input type=text name=question{'25'} value=$answer{'25'} input type=text name=question{'47'} value=$answer{'47'} /form Then when the form came back in, create update statements from the key/value pairs. while (($key,$value) = each %question) { $query = UPDATE tablename SET answer = '$value' WHERE id = '$key' ; } Does that make any sense at all? Can someone tell me how I'd do that in PERL? It makes sense and your solution is close. Rather than using difficult names in your input tags just use simplified names, as just submitting the form won't make your %question spring into life automagically. So given something like: input type=text name=question_45 value=$answer{'45'} input type=text name=question_27 value=$answer{'27'} Then the answers get interpolated in and/or updated by the client end. Then when they submit you will look for something like: my %params = $req-params; while (my ($key, $val) = each (%params)) { if ($key =~ /^question_(\d+)$/) { my $question = $1; my $st = UPDATE tablename SET answer='$val' WHERE id=$question; ... } } This steps through the list of all input parameters, as the names should be unique, looking for a particular criteria, in this case the string 'question_' followed by a set of digits that we know correspond to the ids of the questions. By using the (\d+) we capture that idea into $1, which I then set to $question to make it easy to read. The value associated with that key is your answer. I tried to make this verbose, there is shorter typing that would get the job done and I would suggest using answer=? with a binding value to avoid single quote snafu's, etc. but you get the general idea. It's 'Perl' or 'perl' depending on whether you are talking about the language or the interpreter, but not PERL http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Form field named as array elements
Works like a charm, thanks! Guess I was trying to make it to difficult. I must've done something wrong, though... I had to alter the code a bit to make it work. It seemed that grabbing all the params tossed the param values and I had to go back and get 'em once I had the key isolated. Naming the fields as you suggested: textarea name=question_41 rows=6 cols=60How's this gonna work?/textareabr textarea name=question_40 rows=6 cols=60Still another sample question/textareabr textarea name=question_44 rows=6 cols=60Here's a swell performance question!/textarea And scripting thusly: my $req = new CGI; my @URL_VARS = $req-param; foreach my $VARNAME (@URL_VARS) { if($VARNAME =~ /^question_(\d+)$/) { my $st = UPDATE tablename SET answer = ' . $req-param($VARNAME) . ' WHERE id = '$1'; print $st . br\n; } } Gave me: UPDATE tablename SET answer = 'How's this gonna work?' WHERE id = '41' UPDATE tablename SET answer = 'Still another sample question' WHERE id = '40' UPDATE tablename SET answer = 'Here's a swell performance question!' WHERE id = '44' That's what I get for having templates and trying to go by memory. 'params' gives you (like you found) the list of all parameters, and your adjustments are correct for that case, to work it the way I usually do (and as it is in my own templates) you would do something like: my %params = $request-Vars; while (my ($key, $val) = each (%params)) { # yada, yada, yada... } Sorry about that... http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Help Required
perldoc CGI See section : GENERATING A REDIRECTION HEADER my_paste GENERATING A REDIRECTION HEADER print $query-redirect('http://somewhere.else/in/movie/land'); Sometimes you don't want to produce a document yourself, but simply redirect the browser elsewhere, perhaps choosing a URL based on the time of day or the identity of the user. The redirect() function redirects the browser to a different URL. If you use redirection like this, you should not print out a header as well. One hint I can offer is that relative links may not work correctly when you generate a redirection to another document on your site. This is due to a well-intentioned optimization that some servers use. The solution to this is to use the full URL (including the http: part) of the document you are redirecting to. You can also use named arguments: print $query-redirect(-uri='http://somewhere.else/in/movie/land', -nph=1); The -nph parameter, if set to a true value, will issue the correct headers to work with a NPH (no-parse-header) script. This is important to use with certain servers, such as Microsoft Internet Explorer, which expect all their scripts to be NPH. /my_paste José. -Original Message- From: Amit Sharma [mailto:[EMAIL PROTECTED] Sent: Friday, November 14, 2003 7:01 AM To: [EMAIL PROTECTED] Subject: Help Required Hi, I have written one cgi script which gets the input from user and modify one xml file and I got this string as output http://prv-arweb3.Test.com/Remedy/servlet/Servlet?URL=http://asharma.Test.co m/Query1.xmlTURL=http://asharma.Test.com/Remedy1.xsl Here I am getting modified Query1.xml as input and I have to give this command in address bar to get the desired result. Could you please help me to let me know how directly through CGi I can go to the address mentioned above without copying and pasting in address bar. This address will always remain the same only the xml file will change. General Question: In my cgi script I want to open some site let us suppose http://www.google.com How can I do that. Regards, Amit. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] DISCLAIMER This e-mail and any attachment thereto may contain information which is confidential and/or protected by intellectual property rights and are intended for the sole use of the recipient(s) named above. Any use of the information contained herein (including, but not limited to, total or partial reproduction, communication or distribution in any form) by other persons than the designated recipient(s) is prohibited. If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer. Thank you for your cooperation. For further information about Proximus mobile phone services please see our website at http://www.proximus.be or refer to any Proximus agent. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help Required
On Fri, 14 Nov 2003 00:17:29 -0600, Andrew Gaffney wrote: In my cgi script I want to open some site let us suppose http://www.google.com use CGI; my $cgi = new CGI; print $cgi-header; print scriptlocation.href = 'http://www.google.com';/script There is a more correct way to do this using HTTP codes, such as: print HTTP/1.0 302 Found\n; print Location: www.google.com\n\n; Not quite right CGI.pm-wise, as the CGI module _has_ a redirect() function; use CGI; my $cgi = CGI-new(); print $cgi-redirect( 'http://www.google.com/' ); More information: perldoc CGI -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Parsing for base domain
I would like to parse the servername to get the base domain or atleast x.com, x.org, x.net, etc. from something like www.x.com. Can someone give me a regex for that? I guess the scenarios could be as follows: x.com www.x.com host.x.net beta.x.org I think what I want is the value of the left and right of the last dot. thanks, fw - eMail solutions by http://www.swanmail.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
multilined regexp won't return result
I wrote a script that reads the content of a html page (using the LWP module) and puts it into a variable, in my example $result now i would like to snip out a part of that long htmlcode. I am looking for everyting between these two !-- comment -- strings This is a part of the code from $result [html code before] (snip)... !-- Product intro row -- TABLE border=0 cellPadding=3 cellSpacing=0 width=100% TR TD class=TxtProductIntroB/B/TD /TR TR TD class=TxtProductIntroEinleitungBRBRA LONG LONG LONG DESCRIPTION COMES HERE ...BRBR/TD /TR /TABLE !-- Product specification row -- ... (snip) [html code follows] so I did the following: my ($content) = $result =~ m{!-- Product intro row --(.*)!-- Product specification row --}g; but it always returns an empty result. also tryed this : my ($content) = $result =~ m{!-- Product intro row --([^X]*)!-- Product specification row --}g; I know the [^X]* thing is foolish but it worked for some other parts of my script. What am I doing wrong and is there a easy solution or why isn't there one. I am lost Any help appreciated, thanks in advance. Meik Milevczik -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
script to download via http
I am looking for a script or instruction on how to download files via http. I can browse to the directory and download files individually but I want to automate the process and download all files in directory at regular intervals. I cannot use ftp to get files from this directory. any help is appreciated. Richard
Re: references and objects
Sorry I forgot to mention that the package IS an object ;) on 14/11/03 angie ahl said: Hi everyone I'm failing to find something in the manuals (or at least the bit I'm missing ;) I have an package called Event in it I have a subroutine called EventList I want to return an array and 2 scalars. sub EventList { my ($class, %arg) = @_; # load of code here return ([EMAIL PROTECTED], \$startdate, \$enddate); } So far so good (I think) but I don't seem to be able to access it. I've tried all sorts: my $event = Event-new; my @tempres = $event-EventList(skip=0, max=10); my $startdate = $tempres[2]; my $enddate = $tempres[3]; could anyone give me a clue as to how I would get 2 scalars and an array out of an object and what kind of syntax to use to access the returned values. I'm just missing something I'm sure. Thanks Angie -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: peeking at the top or bottom of an array
Is there a way to peek at the top or bottom of an array? for the first element you could peek like: $first = $array[0]; for the last element you could peek like: $last = $array[$#array]; $# indexes the last element of the array. just make sure you use the same array's name in the index after $# - Amit Dan Anderson [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Is there a way to peek at the top or bottom of an array? Sort of like pop or shift but without needing to insert the value back into the array? I suppose I could do something like: my $check_me = pop @array; push @array, $check_me; But that seems kind of inelegant and verbose. Thanks, Dan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: ActiveState 5.8.0 vs 5.8.1
Drieux [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Thursday, Nov 13, 2003, at 14:10 US/Pacific, Bob X wrote: This may not have a difinitive answer. But will the modules I use for 5.8.0 work/be available with 5.8.1? Basically I am using HTML-Template and CGI-Application and those are the ones I would be worried about. yes. the 'hard cut over' was between 5.6 and 5.8 in which underlying XS code based perl modules became incompatible with each other and required that the upgrade from 5.6 to 5.8 include rebuilding all of those modules. the shift from M.N.O to M.N.(O++) is merely a fixit of the underlying M.N.O release and no effort was made to shift the underlying core API. ciao drieux --- Thanks! I upgraded an PPM'd everything and everything is okay. : ) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Parsing for base domain
On Fri, 14 Nov 2003 01:40:35 -0800, perl wrote: I would like to parse the servername to get the base domain or atleast x.com, x.org, x.net, etc. from something like www.x.com. There are modules on http://www.cpan.org/ to do this for you, but if you _only_ have the names you mentioned, you could always split into an array and the retrieve the two last elements of that array; my @parts = split( /\./, $host ); my $left = $parts[-2] || ''; my $right = $parts[-1] || ''; -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
re
X-Spam-Check-By: la.mx.develooper.com X-Spam-Status: No, hits=5.4 required=7.0 tests=CARRIAGE_RETURNS,MAILTO_TO_SPAM_ADDR,NO_MX_FOR_FROM,NO_REAL_NAME,QUOTED_EMAIL_TEXT,SPAM_PHRASE_00_01,SUPERLONG_LINE version=2.44 X-SMTPD: qpsmtpd/0.26, http://develooper.com/code/qpsmtpd/ On Nov 13, 2003, at 1:14 PM, [EMAIL PROTECTED] wrote: Hi- I'm an absolute beginner to Perl. I need to write a script that will take tables from a SQL server database, somehow get them into HTML format, and automatically generate an email to a list of users containing the info I just converted into HTML. All I can seem to find online is generating automatic emails from web forms. Can anyone give me some ideas?? I would appreciate it. I just started a new job and don't want to mess this up.. Before I try to provide some alternative help to this person off-group, could I check this question first. When writing HTML in perl can you interpolate the html with perl code or do you have to write the whole script in perl with each tag within a prel print() function. The importance of this is layout, nested tables, design view in Dreamweaver etc etc - Dreamweaver 4 cannot render the code in design view. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Mechanize
Wow its working now. Must have been staring at the code to long and was missing some obvious type... Thanks!! How can I parse $a-content? I must be missing something. If I try to foreach ($a - content){ if (/someregeq/){ print $_\n; } } It always prints. This is because all of content is look at as 1 element. If I assign it to an array first I get the some kind of response. If I try and use a while loop it just hangs indefinitely. I know this is something easy. Paul -Original Message- From: Kevin Old [mailto:[EMAIL PROTECTED] Sent: Thursday, November 13, 2003 4:51 PM To: [EMAIL PROTECTED] Cc: 'Beginners Perl' Subject: Re: Mechanize On Thu, 2003-11-13 at 16:41, Paul Kraus wrote: Is it possible to connect to a 128bit encrypted web site with www::mechinize? My boss wants me to write a script that will get a daily report for some of our financial web sites and merchant accounts. This is kind of high priority so the sooner you can help the better. This is the address I am trying to connect to https://webproe3.keybank.com/scripts/ndpluginisapi.dll/gtmCmHome/pgAut ho rization But it fails every time returning nothing. Paul Paul, Yes, it can be donethis code works for me: #!/usr/bin/perl # use warnings; use strict; use WWW::Mechanize; my $m = WWW::Mechanize-new; $m-get(https://webproe3.keybank.com/scripts/ndpluginisapi.dll/gtmCmHom e/pgAuthorization); print $m-content(); Hope this helps, Kevin -- Kevin Old [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Counting (easy!)
You need to escape the '@' in your variable: /*** open(FILE, file1); $email = [EMAIL PROTECTED]; while (FILE) { print; print if (/$email/); # $OK = 1 if /$email/; } */ At 04:19 PM 11/13/03 -0500, you wrote: I have a list of email addresses in a text file one to a line. How would I seach for a particular email address? $email = [EMAIL PROTECTED]; while FILE { if ($email eq $_) { $OK = 1; } } It seems the @ symbol somehow doesn't work in this search. What would be a better (or right) way to do this? thanks in advance. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Mechanize
Lol ... Now that is ironic... Should have read ...staring at the code to long and was missing some obvious typo. :) Paul -Original Message- From: Paul Kraus [mailto:[EMAIL PROTECTED] Sent: Friday, November 14, 2003 8:58 AM To: 'Kevin Old' Cc: 'Beginners Perl' Subject: RE: Mechanize Wow its working now. Must have been staring at the code to long and was missing some obvious type... Thanks!! How can I parse $a-content? I must be missing something. If I try to foreach ($a - content){ if (/someregeq/){ print $_\n; } } It always prints. This is because all of content is look at as 1 element. If I assign it to an array first I get the some kind of response. If I try and use a while loop it just hangs indefinitely. I know this is something easy. Paul -Original Message- From: Kevin Old [mailto:[EMAIL PROTECTED] Sent: Thursday, November 13, 2003 4:51 PM To: [EMAIL PROTECTED] Cc: 'Beginners Perl' Subject: Re: Mechanize On Thu, 2003-11-13 at 16:41, Paul Kraus wrote: Is it possible to connect to a 128bit encrypted web site with www::mechinize? My boss wants me to write a script that will get a daily report for some of our financial web sites and merchant accounts. This is kind of high priority so the sooner you can help the better. This is the address I am trying to connect to https://webproe3.keybank.com/scripts/ndpluginisapi.dll/gtmCmHome/pgAut ho rization But it fails every time returning nothing. Paul Paul, Yes, it can be donethis code works for me: #!/usr/bin/perl # use warnings; use strict; use WWW::Mechanize; my $m = WWW::Mechanize-new; $m-get(https://webproe3.keybank.com/scripts/ndpluginisapi.dll/gtmCmHom e/pgAuthorization); print $m-content(); Hope this helps, Kevin -- Kevin Old [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Help Required might not get you help
Greetings! A general thought: Subject lines should tell people what the subject of the e-mail is. On many lists and newsgroups dedicated to programming languages, many of the most knowledgeable people won't bother reading messages with vague subjects like Help Required. They don't want to waste their time on things they might not be able to help with. You will get much better results with subjects like How can I use CGI to go to a URL? Also, this appears to be a CGI question. There is a companion list to this one named [EMAIL PROTECTED] I'm not sure offhand how to sign up for it. You can probably find instructions at www.perl.org. Rob __ Do you Yahoo!? Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Replace with regular expression
Very thanks Jeff and Wiggins, this work perfectly! Regards, Ricardo Pichler - Original Message - From: Jeff 'japhy' Pinyan [EMAIL PROTECTED] To: Ricardo Pichler [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Friday, November 14, 2003 12:27 AM Subject: Re: Replace with regular expression On Nov 13, Ricardo Pichler said: I need replace in my string the characters in upperCase for the same but preceding the simbol +. $myName=RicardoPichler; s/.../.../g; # to do this return +Ricardo+Pichler; $myName=~s/[A-Z]/\+[A-Z]/g; You can't use a regex on the right-hand side of a s///, it's not appropriate. Instead, use capturing parentheses: $myName =~ s/([A-Z])/+$1/g; Another way to do this, though, is to use a look-ahead: $myName =~ s/(?=[A-Z])/+/g; That says if we can look ahead and match an A-Z, then replace what we've matched (which isn't anything, we've only LOOKED) with a +, for all occurrences. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Mechanize
On Fri, 2003-11-14 at 09:02, Paul Kraus wrote: Lol ... Now that is ironic... Should have read ...staring at the code to long and was missing some obvious typo. :) Paul, Have you looked at the POD docs that came with WWW::Mechanize? It clearly shows how to parse the content http://search.cpan.org/~petdance/WWW-Mechanize-0.66/lib/WWW/Mechanize.pm Also, Randal has a wonderful article on WWW::Mechanize at: http://www.stonehenge.com/merlyn/LinuxMag/col47.html Hope this helps, Kevin -- Kevin Old [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Mechanize
Yes I have read the POD in fact I have them printed out in front of me. Unless I am missing something and I doubt I am since I have read it like 4 times. All you can really do using mechanize is parse the content for links and forms. I need to parse out data from the page that is neither a link or form. I need to read the content a line at a time and using a regex find the content I want to isolate. Your second link all though helpful also seems to be only dealing with the above mentioned conditions. Sorry if this seems trivial. I am not new to perl but $a-content() is not working the way I would expect it to behave. The regex I would use is /class=statement align=center/ Paul Kraus -Original Message- From: Kevin Old [mailto:[EMAIL PROTECTED] Sent: Friday, November 14, 2003 9:22 AM To: [EMAIL PROTECTED] Cc: 'Beginners Perl' Subject: RE: Mechanize On Fri, 2003-11-14 at 09:02, Paul Kraus wrote: Lol ... Now that is ironic... Should have read ...staring at the code to long and was missing some obvious typo. :) Paul, Have you looked at the POD docs that came with WWW::Mechanize? It clearly shows how to parse the content http://search.cpan.org/~petdance/WWW-Mechanize-0.66/lib/WWW/Mechanize.pm Also, Randal has a wonderful article on WWW::Mechanize at: http://www.stonehenge.com/merlyn/LinuxMag/col47.html Hope this helps, Kevin -- Kevin Old [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Mechanize
On Fri, 2003-11-14 at 09:36, Paul Kraus wrote: Yes I have read the POD in fact I have them printed out in front of me. Unless I am missing something and I doubt I am since I have read it like 4 times. All you can really do using mechanize is parse the content for links and forms. I need to parse out data from the page that is neither a link or form. I need to read the content a line at a time and using a regex find the content I want to isolate. Your second link all though helpful also seems to be only dealing with the above mentioned conditions. Sorry if this seems trivial. I am not new to perl but $a-content() is not working the way I would expect it to behave. The regex I would use is /class=statement align=center/ Paul, I'd love to help, but don't have anything to test against. Can you send me the results from $a-content so that I can see what you're getting? Couldn't you just save the results from $a-content to a scalar, then use a regex on it? my $results = $a-content(); $results =~ m/what I'm looking for/; Also, from the POD for WWW::Mechanize: Mech is well suited for use in testing web applications. If you use one of the Test::*, like Test::HTML::Lint modules, you can check the fetched content and use that as input to a test call. use Test::More; like( $a-content(), qr/$expected/, Got expected content ); Hope this helps, Kevin -- Kevin Old [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Mechanize
Ok here is a sample of the data. Its very confidential so I am trying to be selective on what I send. I am just including the header information since its not going to be dangerous to send :) Basically a table exists on this page that has merchant transaction info like this... The only lines on these pages that have dat that I need all have class=statement and align=center in the td tag... Thanks for all your help. Paul tr tr td class=statement valign=top align=centerSettlementbrDate/td td class=statement valign=top align=centerTerminal ID/td td class=statement valign=top align=centerBatch ControlbrNumber/td td class=statement valign=top align=right NetbrAmount/td td class=statement valign=top align=centerItems/td /tr -Original Message- From: Kevin Old [mailto:[EMAIL PROTECTED] Sent: Friday, November 14, 2003 9:47 AM To: [EMAIL PROTECTED] Cc: 'Beginners Perl' Subject: RE: Mechanize On Fri, 2003-11-14 at 09:36, Paul Kraus wrote: Yes I have read the POD in fact I have them printed out in front of me. Unless I am missing something and I doubt I am since I have read it like 4 times. All you can really do using mechanize is parse the content for links and forms. I need to parse out data from the page that is neither a link or form. I need to read the content a line at a time and using a regex find the content I want to isolate. Your second link all though helpful also seems to be only dealing with the above mentioned conditions. Sorry if this seems trivial. I am not new to perl but $a-content() is not working the way I would expect it to behave. The regex I would use is /class=statement align=center/ Paul, I'd love to help, but don't have anything to test against. Can you send me the results from $a-content so that I can see what you're getting? Couldn't you just save the results from $a-content to a scalar, then use a regex on it? my $results = $a-content(); $results =~ m/what I'm looking for/; Also, from the POD for WWW::Mechanize: Mech is well suited for use in testing web applications. If you use one of the Test::*, like Test::HTML::Lint modules, you can check the fetched content and use that as input to a test call. use Test::More; like( $a-content(), qr/$expected/, Got expected content ); Hope this helps, Kevin -- Kevin Old [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Mechanize
I was way over thinking this. A simply split command to break the scalar content up by \n solved my problems. Paul -Original Message- From: Kevin Old [mailto:[EMAIL PROTECTED] Sent: Friday, November 14, 2003 9:47 AM To: [EMAIL PROTECTED] Cc: 'Beginners Perl' Subject: RE: Mechanize On Fri, 2003-11-14 at 09:36, Paul Kraus wrote: Yes I have read the POD in fact I have them printed out in front of me. Unless I am missing something and I doubt I am since I have read it like 4 times. All you can really do using mechanize is parse the content for links and forms. I need to parse out data from the page that is neither a link or form. I need to read the content a line at a time and using a regex find the content I want to isolate. Your second link all though helpful also seems to be only dealing with the above mentioned conditions. Sorry if this seems trivial. I am not new to perl but $a-content() is not working the way I would expect it to behave. The regex I would use is /class=statement align=center/ Paul, I'd love to help, but don't have anything to test against. Can you send me the results from $a-content so that I can see what you're getting? Couldn't you just save the results from $a-content to a scalar, then use a regex on it? my $results = $a-content(); $results =~ m/what I'm looking for/; Also, from the POD for WWW::Mechanize: Mech is well suited for use in testing web applications. If you use one of the Test::*, like Test::HTML::Lint modules, you can check the fetched content and use that as input to a test call. use Test::More; like( $a-content(), qr/$expected/, Got expected content ); Hope this helps, Kevin -- Kevin Old [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: script to download via http
Richard Foley wrote: I am looking for a script or instruction on how to download files via http. I can browse to the directory and download files individually but I want to automate the process and download all files in directory at regular intervals. I cannot use ftp to get files from this directory. Hi Richard. Unlike FTP, HTTP doesn't allow you to retrieve a directory list. You need to know beforehand what's already there. HTTP servers can be set up to return a listing for a directory if no file is specified, but in general it's set up so that you can see only links from public pages. If you already know what the files are called, then LWP::Simple will do what you need. If you don't then you need to be able to parse things like 'index.htm' to find linked files. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help Required might not get you help
Rob Richardson wrote: A general thought: Subject lines should tell people what the subject of the e-mail is. On many lists and newsgroups dedicated to programming languages, many of the most knowledgeable people won't bother reading messages with vague subjects like Help Required. They don't want to waste their time on things they might not be able to help with. You will get much better results with subjects like How can I use CGI to go to a URL? Although in practise you'll probably rally support if you post something like: From:Rapunzel Subject: Help! I'm stuck at the top of this tower! Sad, isn't it :) Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Mechanize
Ok here is a sample of the data. Its very confidential so I am trying to be selective on what I send. I am just including the header information since its not going to be dangerous to send :) Basically a table exists on this page that has merchant transaction info like this... The only lines on these pages that have dat that I need all have class=statement and align=center in the td tag... Thanks for all your help. Paul tr tr td class=statement valign=top align=centerSettlementbrDate/td td class=statement valign=top align=centerTerminal ID/td td class=statement valign=top align=centerBatch ControlbrNumber/td td class=statement valign=top align=right NetbrAmount/td td class=statement valign=top align=centerItems/td /tr You seem to have found your solution, but this is a good example of why parsing HTML with simple regexes is probably not a good idea. A true HTML parser would have probably simplified matters had it been used from the start and will make future changes easier to manage, may I suggest: HTML::TokeParser::Simple I have found it very agreeable... http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: references and objects [Solved]
I changed my code so the variables aren't references; sub EventList { my ($class, %arg) = @_; # load of code here return ([EMAIL PROTECTED], $startdate, $enddate); } And then called it like so: my @tempres = $event-EventList(skip=0, max=10); my $EventList = @tempres[0]; my @EventList = @{$EventList}; my $startdate = @tempres[1]; my $enddate = @tempres[2]; Angie I have an package called Event in it I have a subroutine called EventList I want to return an array and 2 scalars. sub EventList { my ($class, %arg) = @_; # load of code here return ([EMAIL PROTECTED], \$startdate, \$enddate); } So far so good (I think) but I don't seem to be able to access it. I've tried all sorts: my $event = Event-new; my @tempres = $event-EventList(skip=0, max=10); my $startdate = $tempres[2]; my $enddate = $tempres[3]; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Help Required might not get you help
Rob Richardson [EMAIL PROTECTED] wrote: : : A general thought: Subject lines should tell people what the : subject of the e-mail is. On many lists and newsgroups : dedicated to programming languages, many of the most : knowledgeable people won't bother reading messages with vague : subjects like Help Required. They don't want to waste their : time on things they might not be able to help with. You will : get much better results with subjects like How can I use CGI : to go to a URL? I don't frequent the USENET much any more, but I used to filter certain questions out by using the subject. As I recall I marked posts as read that had the words newbie or new to perl and urgent in them. Being new to perl did not mean you had to be new to USENET. And it didn't mean you had to ignore the common courtesies that had been established. At first I thought it a bit unfair to arbitrarily mark a post (or a poster) because they had obviously never read the etiquette rules for USENET. But the shear volume of messages requires at least some filtering. My first attempts marked areas I did not possess an interest. Even then, I would often read posts from people who either disregarded netiquette or had never read them. After a few months I started blocking senders. I like to share my knowledge with others, but I appreciate those who take the time to properly ask questions. There are a lot of people who post correctly. Why bother with the people who can't be bothered to use good subjects, use sentence case, capitalize i or spell out words like are? (And started blocking anyone who top-posted.) Here I am taking the time to reply, double check my sources, test any code I include, and proof-read my message and I need to continually click on the ignore button of my spell-checker as it catches errors in the quoted text. I tend to be more lenient here on these lists, but I monitor three perl beginner lists and they are all dumped into one folder. Some days are busy and I'll look at messages with descriptive subjects first. Sometimes I don't get to the non-descriptive subjects. Some days I feel like starting a message board for people who like to help on message boards. Then I could post quotes from particularly annoying posts in the Look what the Idiots Posted Today forum. :) Charles K. Clarkson -- Head Bottle Washer, Clarkson Energy Homes, Inc. Mobile Home Specialists 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: When is Perl 6 coming out?
Km == Km [EMAIL PROTECTED] writes: Km i am just curious -- is perl 6 coming with a compiler ? Why would they remove a feature already available since Perl 1? Perl has *always* been compiled. Recent Perls even let you get at it a bit easier. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Starting Perl
Chuk == Chuk Goodin [EMAIL PROTECTED] writes: Chuk Sort of both, but more of the former. Basically, if I've got a Chuk directory sitting there with three or four different types of Chuk files in it, I'd like to know which ones are perl (and I can Chuk just open them up in vi and fix them) and which ones aren't (and Chuk I'll have to find the source somewhere if I need to fix them). Chuk Right now I use .pl for that. Why do you need to know that before going in to the file? If the program frazzy is broken, you go to frazzy. Why do you want to know that's Perl already? And if you need to know, file frazzy will tell you precisely what it has. Extensions for programs convey redundant useless information, and serve only to distract. Please don't use them on Unix. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Starting Perl
Chris == Chris McMahon [EMAIL PROTECTED] writes: Chris I name my Perl scripts on my FreeBSD box something.pl Chris because I'm the first (and so far only, but not for long) user Chris of a Unix-y system in an all-Windows shop, and I don't want my Chris colleagues to be confused. If they're using Windows, they're already hopelessly confused. :) -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: validate email chars
perl == perl [EMAIL PROTECTED] writes: perl Can someone help me with validating email address chars? perl I think I have the back part ok. I just need to verify the front of the @ perl sign to have atleast 4 chars, start with a-Z allows \w\-\. Thus keeping my legitmate email address of fred[EMAIL PROTECTED] from entering into your form. Wrong. Very wrong. (That's an autoreponder... try it!) -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: multilined regexp won't return result
Hi. You're not inviting people to reply to you because: - you don't have a real name in your 'From:' (You have a personal mail account, so why not supply your name?) - You have a line in your message 127 characters long, which isn't helped by your 24-character indent. (Try to summarise your post within a 72-character margin. If example data exceeds that then attach it instead of putting it in-line) It took me about five minutes to see your intention, 'midst the winter snow, but your problem is that you have multi-line data which you expect to be spanned by (.*). If you add the /s (single-line) qualifier to your regex test then a dot will also match \n. HTH, Rob [EMAIL PROTECTED] wrote: I wrote a script that reads the content of a html page (using the LWP module) and puts it into a variable, in my example $result now i would like to snip out a part of that long htmlcode. I am looking for everyting between these two !-- comment -- strings This is a part of the code from $result [html code before] (snip)... !-- Product intro row -- TABLE border=0 cellPadding=3 cellSpacing=0 width=100% TR TD class=TxtProductIntroB/B/TD /TR TR TD class=TxtProductIntroEinleitungBRBRA LONG LONG LONG DESCRIPTION COMES HERE ...BRBR/TD /TR /TABLE !-- Product specification row -- ... (snip) [html code follows] so I did the following: my ($content) = $result =~ m{!-- Product intro row --(.*)!-- Product specification row --}g; but it always returns an empty result. also tryed this : my ($content) = $result =~ m{!-- Product intro row --([^X]*)!-- Product specification row --}g; I know the [^X]* thing is foolish but it worked for some other parts of my script. What am I doing wrong and is there a easy solution or why isn't there one. I am lost Any help appreciated, thanks in advance. Meik Milevczik -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: references and objects
On Fri, Nov 14, 2003 at 11:40:51AM +, angie ahl wrote: I want to return an array and 2 scalars. sub EventList { my ($class, %arg) = @_; # load of code here return ([EMAIL PROTECTED], \$startdate, \$enddate); } So far so good (I think) You're actually returning references to the array and scalars, which might not be what you wanted. but I don't seem to be able to access it. I've tried all sorts: my $event = Event-new; my @tempres = $event-EventList(skip=0, max=10); my $startdate = $tempres[2]; my $enddate = $tempres[3]; sub foo { my $x = 'x'; my $y = 'y'; my @z = qw(several values); return ($x, $y, @z); # flatten into a list (no references) } my ($x, $y, @z) = foo(); # @z slurps the rest of the list -- Steve -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Starting Perl
OK, I just can't leave this one alone, I have to know... =) You *are* the one who wrote Learning Perl on Win32 Systems, yes? The more-or-less definitive guide to arguably the most powerful Windows scripting language around? Were you an entirely different person in 1997? Posessed by MS demons, maybe? Is there anything you need to confess? I sense some interesting Perl history here... Apologies in advance, and please read this message with the kindness that I wrote it (and also feel free to ignore it!)... -Chris -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, November 14, 2003 8:29 AM To: [EMAIL PROTECTED] Subject: Re: Starting Perl Chris == Chris McMahon [EMAIL PROTECTED] writes: Chris I name my Perl scripts on my FreeBSD box something.pl Chris because I'm the first (and so far only, but not for long) user Chris of a Unix-y system in an all-Windows shop, and I don't want my Chris colleagues to be confused. If they're using Windows, they're already hopelessly confused. :) -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Parsing for base domain
On Nov 14, [EMAIL PROTECTED] said: I would like to parse the servername to get the base domain or atleast x.com, x.org, x.net, etc. from something like www.x.com. You're sure you won't run into www.foo.co.uk domains? I think what I want is the value of the left and right of the last dot. Here's one way: ($last_part) = $domain =~ /.*\.(.*\..*)/; A slightly more verbose way is: $last_part = substr( $domain, 1 + rindex($domain, '.', rindex($domain, '.')) ); -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
How do you dynamically assign array names?
Hi, I am trying to initialize a dynamically-named array, i.e. with the following test code (if I type script.pl char at the command prompt) I get the message array char contains 1 2 3 but I get a warning if 'use strict' is on. Can anyone show me how it should be done (I would like to use 'use strict'!)? #!/usr/bin/perl -w #use strict; my ($string); while ($ARGV[0]) { chomp($string=$_); @$string = (1,2,3); #Won't work if 'use strict' pragma is used } print array $string contains @$string\n; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Starting Perl
Chris == McMahon, Chris [EMAIL PROTECTED] writes: Chris You *are* the one who wrote Learning Perl on Win32 Systems, yes? I wrote the Learning Perl parts yes. Eric Olsen (I'm probably mangling the spelling of his name) wrote the Win32 parts though. I didn't even know the book was coming out until it showed up on shelves. :-) Luckily, with the modern Learning Perl book, there's no need for a separate version. O'Reilly continues to sell it though, simply because it's selling. :) We've come a long way from that first series of books. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: references and objects
On Nov 14, angie ahl said: I want to return an array and 2 scalars. Well, you're returning an array reference and two scalar references. I don't think the scalars need to be referenced, but I would probably keep the array reference. sub EventList { my ($class, %arg) = @_; # load of code here return ([EMAIL PROTECTED], \$startdate, \$enddate); } return ($startdate, $enddate, [EMAIL PROTECTED]); my $event = Event-new; my @tempres = $event-EventList(skip=0, max=10); my $startdate = $tempres[2]; my $enddate = $tempres[3]; You'd need $tempres[1] and $tempres[2], since arrays are 0-based, but you'd also need ${ $tempres[1] } and ${ $tempres[2] }, since you're returning references to those scalars. Using my return values, you'd do: my ($start, $end, $listref) = $event-EventList(skip = 0, max = 10); -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How do you dynamically assign array names?
On Nov 14, Douglas Houston said: I am trying to initialize a dynamically-named array, i.e. with the following test code (if I type script.pl char at the command prompt) I get the message array char contains 1 2 3 but I get a warning if 'use strict' is on. Can anyone show me how it should be done (I would like to use 'use strict'!)? You need to explain WHY you want to do this. There doesn't seem to me to be a good reason. Use a hash of array references. Don't turn off strict. #!/usr/bin/perl use strict; use warnings; # perl5.6+ my %data; my $name = shift; $data{$name} = [1,2,3]; # or # @{ $data{$name} } = (1,2,3); And your while ($ARGV[0]) is weird, and not working why you think it works. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How do you dynamically assign array names?
Douglas == Douglas Houston [EMAIL PROTECTED] writes: Douglas I am trying to initialize a dynamically-named array, Douglas i.e. with the following test code (if I type script.pl char Douglas at the command prompt) I get the message array char contains Douglas 1 2 3 but I get a warning if 'use strict' is on. Can anyone Douglas show me how it should be done (I would like to use 'use Douglas strict'!)? It should be done by not doing it. Do not use data to define metadata (like variable names). Down that path lies madness. use strict is trying to keep you from going mad. Probably what you are looking for is a hash containing arrayrefs, pointing at your real data. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How do you dynamically assign array names?
Hi, I am trying to initialize a dynamically-named array, i.e. with the following test code (if I type script.pl char at the command prompt) I get the message array char contains 1 2 3 but I get a warning if 'use strict' is on. Can anyone show me how it should be done (I would like to use 'use strict'!)? #!/usr/bin/perl -w #use strict; my ($string); while ($ARGV[0]) { chomp($string=$_); @$string = (1,2,3); #Won't work if 'use strict' pragma is used } print array $string contains @$string\n; Well that is kind of the point, you don't :-). That is specifically what the 'refs' part of 'strict' prevents (symbolic references), for good reason. perldoc strict In newer Perls you can shut off that portion of the stricture lexically, or a better idea is to store a reference to an anonymous array to a hash, then use the hash key as its name. my %hash; $hash{'array_name'} = [ 'one','two','three' ]; print $hash{'array_name'}-[2]; perldoc perlreftut perldoc perlref http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How do you dynamically assign array names?
To complete previous posts, have a look to this: Subject: Why it's stupid to `use a variable as a variable name' http://perl.plover.com/varvarname.html José. -Original Message- From: Douglas Houston [mailto:[EMAIL PROTECTED] Sent: Friday, November 14, 2003 4:55 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: How do you dynamically assign array names? Hi, I am trying to initialize a dynamically-named array, i.e. with the following test code (if I type script.pl char at the command prompt) I get the message array char contains 1 2 3 but I get a warning if 'use strict' is on. Can anyone show me how it should be done (I would like to use 'use strict'!)? #!/usr/bin/perl -w #use strict; my ($string); while ($ARGV[0]) { chomp($string=$_); @$string = (1,2,3); #Won't work if 'use strict' pragma is used } print array $string contains @$string\n; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] DISCLAIMER This e-mail and any attachment thereto may contain information which is confidential and/or protected by intellectual property rights and are intended for the sole use of the recipient(s) named above. Any use of the information contained herein (including, but not limited to, total or partial reproduction, communication or distribution in any form) by other persons than the designated recipient(s) is prohibited. If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer. Thank you for your cooperation. For further information about Proximus mobile phone services please see our website at http://www.proximus.be or refer to any Proximus agent. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How do you dynamically assign array names?
On Fri, 14 Nov 2003, Jeff 'japhy' Pinyan wrote: On Nov 14, Douglas Houston said: I am trying to initialize a dynamically-named array, i.e. with the following test code (if I type script.pl char at the command prompt) I get the message array char contains 1 2 3 but I get a warning if 'use strict' is on. Can anyone show me how it should be done (I would like to use 'use strict'!)? You need to explain WHY you want to do this. There doesn't seem to me to be a good reason. Use a hash of array references. Don't turn off strict. WHY do I need to explain why I want to do this? There certainly isn't a good reason to do it with the test code I posted. If there's NEVER a good reason, what are the alternatives? And your while ($ARGV[0]) is weird, and not working why you think it works. Can you a) explain how I think it works, and b) explain why it really works. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How do you dynamically assign array names?
On Nov 14, Douglas Houston said: On Fri, 14 Nov 2003, Jeff 'japhy' Pinyan wrote: On Nov 14, Douglas Houston said: I am trying to initialize a dynamically-named array, i.e. with the following test code (if I type script.pl char at the command prompt) I get the message array char contains 1 2 3 but I get a warning if 'use strict' is on. Can anyone show me how it should be done (I would like to use 'use strict'!)? You need to explain WHY you want to do this. There doesn't seem to me to be a good reason. Use a hash of array references. Don't turn off strict. WHY do I need to explain why I want to do this? There certainly isn't a good reason to do it with the test code I posted. If there's NEVER a good reason, what are the alternatives? You need to explain why you want to do it is because it can create problems down the line. As for an alternative, I told you and showed you: use a hash of array references. $hash{foo} = [10, 20, 30]; print $hash{foo}[2]; # 30 And your while ($ARGV[0]) is weird, and not working why you think it works. a) explain how I think it works, and I don't know how you think it works, I'm just quite sure that you're using that construct because you think it is a standard thing to do, and it's not. How do YOU think it works? What if the first argument to your program was foo*? b) explain why it really works. Perl thinks you're doing a file glob. XXX is a read from a filehandle unless XXX is something more complex than an identifier or a simple scalar. Thus, $foo[$x] is a file glob, glob($foo[$x]). If $foo[$x] has any wildcards or such, the shell expands that glob to all the files matching the pattern. But if it's just 'blah', glob('blah') returns 'blah'. Then, the next time, it returns undef, because it's done returning them. If that sounds complex, that's because it IS. Doing what you did works in some cases, for a bizarre reason. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How do you dynamically assign array names?
Douglas Houston [mailto:[EMAIL PROTECTED] : : WHY do I need to explain why I want to do this? Because no one wants to give a loaded gun to someone who hasn't demonstrated a good grasp of gun safety. HTH, Charles K. Clarkson -- Head Bottle Washer, Clarkson Energy Homes, Inc. Mobile Home Specialists 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How do you dynamically assign array names?
Douglas Houston [mailto:[EMAIL PROTECTED] : : WHY do I need to explain why I want to do this? Because no one wants to give a loaded gun to someone who hasn't demonstrated a good grasp of gun safety. That is a very ironic response coming from someone who based on their sig I assume is in the US, going to someone based on their address appears to be in the UK... who'd a thunk it... http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How do you dynamically assign array names?
On Fri, Nov 14, 2003 at 04:30:05PM +, Douglas Houston wrote: On Fri, 14 Nov 2003, Jeff 'japhy' Pinyan wrote: On Nov 14, Douglas Houston said: I am trying to initialize a dynamically-named array You need to explain WHY you want to do this. There doesn't seem to me to be a good reason. Use a hash of array references. Don't turn off strict. WHY do I need to explain why I want to do this? There certainly isn't a good reason to do it with the test code I posted. Probably Jeff was being polite, giving you the benefit of the doubt, allowing you to remain innocent-until-proven-guilty, etc. The fact is, there are very few good reasons to use symrefs -- exporting symbols is the only one I can think of -- and if you have a good reason, you'll need to give us some more information. If there's NEVER a good reason, It's not that there's NEVER a good reason to use symbolic references. It's just that the code you posted doesn't have one. :-) what are the alternatives? Use a hash of array references. Instead of this: @$name = (1,2,3);# gack! what if $name is _ or INC? use this. $hash{$name} = [1,2,3]; And your while ($ARGV[0]) is weird, and not working why you think it works. Can you a) explain how I think it works, and I don't know what you think the angle-brackets do here, but... b) explain why it really works. Unless you think they do filename globbing, that code isn't working the way you think it works. -- Steve -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How do you dynamically assign array names?
Douglas Houston wrote: On Fri, 14 Nov 2003, Jeff 'japhy' Pinyan wrote: On Nov 14, Douglas Houston said: I am trying to initialize a dynamically-named array, i.e. with the following test code (if I type script.pl char at the command prompt) I get the message array char contains 1 2 3 but I get a warning if 'use strict' is on. Can anyone show me how it should be done (I would like to use 'use strict'!)? You need to explain WHY you want to do this. There doesn't seem to me to be a good reason. Use a hash of array references. Don't turn off strict. WHY do I need to explain why I want to do this? There certainly isn't a good reason to do it with the test code I posted. If there's NEVER a good reason, what are the alternatives? Jeff's pretty sharp. Believe him. And don't be rude to people if you're asking for a favour. How can anyone suggest what the 'alternatives' may be without an explanation of the problem? Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How do you dynamically assign array names?
Wiggins D Anconia wrote: Douglas Houston [mailto:[EMAIL PROTECTED] : : WHY do I need to explain why I want to do this? Because no one wants to give a loaded gun to someone who hasn't demonstrated a good grasp of gun safety. That is a very ironic response coming from someone who based on their sig I assume is in the US, going to someone based on their address appears to be in the UK... who'd a thunk it... I would have thought it were more ironic the other way around. Everybody expects an American gun slinger to threaten a peaceful Dundee land owner. Totally :-)) No flames thank you. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Capturing system call output value
Can someone help me with capturing an output of a system() call? ie ($a)=system(uname -n); where $a would have the output value. thanks - eMail solutions by http://www.swanmail.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Capturing system call output value
Can someone help me with capturing an output of a system() call? ie ($a)=system(uname -n); where $a would have the output value. perldoc -q 'output of a command' You want backticks instead, though there are better ways to come by the sysem name, and don't use $a ($name) = `uname -n`; See the Sys::Hostname module... http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Capturing system call output value
Thanks that help. but I notice there is a newline included in the variable when using the ($name)=`uname -n`; Is this a normal thing that I should strip? Can someone help me with capturing an output of a system() call? ie ($a)=system(uname -n); where $a would have the output value. perldoc -q 'output of a command' You want backticks instead, though there are better ways to come by the sysem name, and don't use $a ($name) = `uname -n`; See the Sys::Hostname module... http://danconia.org - eMail solutions by http://www.swanmail.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Capturing system call output value
Chomp Ned Cunningham POS Systems Development Monro Muffler Brake 200 Holleder Parkway Rochester, NY 14615 (585) 647-6400 ext. 310 [EMAIL PROTECTED] -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, November 14, 2003 1:49 PM To: Wiggins d Anconia Cc: [EMAIL PROTECTED] Subject:Re: Capturing system call output value Thanks that help. but I notice there is a newline included in the variable when using the ($name)=`uname -n`; Is this a normal thing that I should strip? Can someone help me with capturing an output of a system() call? ie ($a)=system(uname -n); where $a would have the output value. perldoc -q 'output of a command' You want backticks instead, though there are better ways to come by the sysem name, and don't use $a ($name) = `uname -n`; See the Sys::Hostname module... http://danconia.org - eMail solutions by http://www.swanmail.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: When is Perl 6 coming out?
Randal L. Schwartz wrote: : Km == Km [EMAIL PROTECTED] writes: Km i am just curious -- is perl 6 coming with a compiler ? Why would they remove a feature already available since Perl 1? [snip] I think you and I both know what Km means by a 'compiler'. Did your first train ride come with an 'engine'? Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Using Net::FTP for chmod (help needed ASAP)
Hi, Much to my surprise, when I run this code, it never returns 0 if it could not carry out the operation. $rc = $f-site(chmod 666 $remoteFile) or die ftp: Could not change permissions: $!\n; It seems to return a 2 on success, and a 5 if it could not access the file because of a different owner. My question is, what return code can I rely on? I need to be sure the permissions were set to '666'. Any suggestions? This is a emergency quick fix. Thanks in advance -Jeff __ Do you Yahoo!? Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How do you dynamically assign array names?
Douglas Houston wrote: Hi, I am trying to initialize a dynamically-named array, i.e. with the following test code (if I type script.pl char at the command prompt) I get the message array char contains 1 2 3 but I get a warning if 'use strict' is on. Can anyone show me how it should be done (I would like to use 'use strict'!)? #!/usr/bin/perl -w #use strict; my ($string); while ($ARGV[0]) { chomp($string=$_); @$string = (1,2,3); #Won't work if 'use strict' pragma is used } print array $string contains @$string\n; this normally can't be done cleanly and is generally not recommanded given there are other ways to accomplish bascially the same thing. but if you are here to see if it can be done at all, you might want to try something like: #!/usr/bin/perl -w use strict; my $name = shift; eval CODE; no strict; @ $name=1..3; print \$_\\n for(@ $name); CODE #-- #-- print it again after eval #-- while(my($k,$v) = each %::){ next unless($k =~ /^$name$/); local *sym = $v; print join(\n,@main::sym),\n; } __END__ prints: 1 2 3 1 2 3 david -- $_='015001450154015401570040016701570162015401440' ,*,=*|=*_,split+local$;map{~$_1{$,=1,$#.=qq~ /[EMAIL PROTECTED]||3])=~}}0..s,.,,g-01;*_=*#,s [[s/eval+w/.`9`/e]]n\\xng.print+eval(evalqq`$_`) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How do you dynamically assign array names?
On Fri, Nov 14, 2003 at 12:25:41PM -0800, david wrote: Douglas Houston wrote: I am trying to initialize a dynamically-named array this normally can't be done cleanly and is generally not recommanded given there are other ways to accomplish bascially the same thing. but if you are here to see if it can be done at all, you might want to try something like: #!/usr/bin/perl -w use strict; my $name = shift; eval CODE; no strict; @ $name=1..3; print \$_\\n for(@ $name); CODE Sigh... :-) The point is not that *symrefs* are inherently bad. The point is that turning data into variable names can cause huge, nightmarish maintenance problems. Even though your code doesn't have any symbolic references, it can still cause all the same maintenance problems... and it's so much uglier than just using symrefs in the first place! while(my($k,$v) = each %::){ next unless($k =~ /^$name$/); local *sym = $v; print join(\n,@main::sym),\n; } For that matter, you can set the values by munging the symbol table: use strict; my $name = 'foo'; $::{$name} = [1,2,3]; # LHS is a glob print @{ $::{$name} }\n; no strict 'vars'; print @foo\n; But why use the symbol table at all? That's more dangerous than using a regular hash, and more awkward than using the symbolic references. -- Steve -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How do you dynamically assign array names?
David wrote: this normally can't be done cleanly and is generally not recommanded given there are other ways to accomplish bascially the same thing. Steve Grazzini wrote: But why use the symbol table at all? That's more dangerous than using a regular hash, and more awkward than using the symbolic references. didn't i already mention that? :-) david -- $_='015001450154015401570040016701570162015401440' ,*,=*|=*_,split+local$;map{~$_1{$,=1,$#.=qq~ /[EMAIL PROTECTED]||3])=~}}0..s,.,,g-01;*_=*#,s [[s/eval+w/.`9`/e]]n\\xng.print+eval(evalqq`$_`) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Using Net::FTP for chmod (help needed ASAP)
Wiggins d Anconia [EMAIL PROTECTED] wrote: Hi, Much to my surprise, when I run this code, it never returns 0 if it could not carry out the operation. $rc = $f-site(chmod 666 $remoteFile) or die ftp: Could not change permissions: $!\n; It seems to return a 2 on success, and a 5 if it could not access the file because of a different owner. My question is, what return code can I rely on? I need to be sure the permissions were set to '666'. Any suggestions? This is a emergency quick fix. Thanks in advance From the docs: Returns most significant digit of the response code. The response code is part of the FTP specification, response codes in the 200's are successes and responses in the 500's are failures, so it should be sufficient to check for a 2 and have that be success, a 5 makes failure and anything else is undefined. By looking at the 2 lesser significant digits normally a failure cause can be determined, but with 'site' that is system dependent (at least I think). This makes sense (now). Silly me, I thought non-zero was success. Using a truncated number from the RFC was definitely a mystery. I wish these packages followed a stricter standard. This helped tremendously, and I've resorted to using something like $perm = substr(sprintf(%s, $f-dir($remoteFile)), 1, 9); die Bad permissions\n unless ($perm =~ /rw-rw-rw-/); Thanks again! =) -Jeff __ Do you Yahoo!? Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How do you dynamically assign array names?
On Fri, Nov 14, 2003 at 01:24:53PM -0800, david wrote: David wrote: this normally can't be done cleanly and is generally not recommanded given there are other ways to accomplish bascially the same thing. Steve Grazzini wrote: But why use the symbol table at all? That's more dangerous than using a regular hash, and more awkward than using the symbolic references. didn't i already mention that? :-) Yeah... There's just a long tradition of telling people how to use eval() and %:: to get strict-safe-symrefs, and an equally long tradition of smacking whomever does it. :-) -- Steve -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: external sub routine
On Friday, Nov 14, 2003, at 18:38 US/Pacific, David Inglis wrote: I have a some code that will be used in a number of my scripts, I know that if I have a sub in a script I can call that piece of code as many times as required from the same script but how do I make this sub vailable to other scripts I have written. I imagine that I create a seperate script with this code and somehow include this or call it. What you will ultimately want to do is move on to creating your first Perl Module. I have my general rant on PM's at: http://www.wetware.com/drieux/CS/lang/Perl/PM/ it of course suggests that you visit http://www.wetware.com/drieux/CS/Proj/PID/ where I show how to use h2xs, where it show you at http://www.wetware.com/drieux/CS/Proj/PID/#TheTypeScript the output of the h2xs and the basic form of a perl module that it will create. you will of course want to read perldoc perlsub Perl subroutines perlmod Perl modules: how they work perlmodlib Perl modules: how to write and use perlmodinstall Perl modules: how to install from CPAN the other strategy is to go with perl's OO-ish approach and that would start out a bit simpler in template form package Foo::Bar; use 5.006; use strict; use warnings; our $VERSION = '0.01'; sub new { my $type = shift; my $class = ref($type) || $type; my $self = {}; bless $self, $class; } # end of our simple new #- # so that AUTOLOAD finds one here sub DESTROY {} # # your methods here # 1; # so that the 'use Foo::Bar' will know we are happy ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
text replacement+
Hi everyone, I have a following data to analyze : - BlockA color 0 0 0 rcolor 1 1 1 dcolor 2 2 2 BloackB color 0 0 0 rcolor 1 1 1 dcolor 2 2 2 (...and so on) - I want to replace BlockA rcolor 1 1 1 to 4 4 4 and BlockB rcolor 1 1 1 to 0 0 0. I have variables like $BlockA_rcolor = rcolor 4 4 4. - while (IN) { if ( $_ =~ m/rcolor/ ) { $_ = $BlockA_rcolor; } print $_; } - Above code will replace all 'rcolor' lines in the data. Can anyone please give me an idea, what kind of method I could use ? If my question doesn't have enough information, please let me know. Thanks in advance! -kiko -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: text replacement+
On Nov 14, 2003, at 3:57 PM, Kiko Uehara wrote: Hi everyone, Howdy. I have a following data to analyze : - BlockA color 0 0 0 rcolor 1 1 1 dcolor 2 2 2 BloackB color 0 0 0 rcolor 1 1 1 dcolor 2 2 2 (...and so on) - With ya so far. I want to replace BlockA rcolor 1 1 1 to 4 4 4 and BlockB rcolor 1 1 1 to 0 0 0. Well, that should be pretty easy. Let's see what we can think up... I have variables like $BlockA_rcolor = rcolor 4 4 4. Why don't we change that to a hash. Something like: my %changes = ( BlockA_rcolor = '4 4 4', BlockB_rcolor = '0 0 0' ); - while (IN) { if ( $_ =~ m/rcolor/ ) { $_ = $BlockA_rcolor; } print $_; } - Above code will replace all 'rcolor' lines in the data. It sure will, now let's see if we can use the hash to make it more flexible: my $block; while (IN) { if (/^(Block[A-Z]+)/) { $block = $1; } elsif (/^\s+([rd]?color)/) { my $color = $1; s/\d+ \d+ \d+$/$changes{${block}_$color}/ if exists $changes{${block}_$color}; } } Can you follow how that works? It makes it easy to update ANY color in ANY block. Just add the right hash entry. Can anyone please give me an idea, what kind of method I could use ? If my question doesn't have enough information, please let me know. Your question was perfect. Good luck. James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How do you dynamically assign array names?
Steve Grazzini wrote: On Fri, Nov 14, 2003 at 12:25:41PM -0800, david wrote: Douglas Houston wrote: I am trying to initialize a dynamically-named array this normally can't be done cleanly and is generally not recommanded given there are other ways to accomplish bascially the same thing. but if you are here to see if it can be done at all, you might want to try something like: #!/usr/bin/perl -w use strict; my $name = shift; eval CODE; no strict; @ $name=1..3; print \$_\\n for(@ $name); CODE Sigh... :-) The point is not that *symrefs* are inherently bad. The point is that turning data into variable names can cause huge, nightmarish maintenance problems. Even though your code doesn't have any symbolic references, it can still cause all the same maintenance problems... and it's so much uglier than just using symrefs in the first place! Thanks Steve. I agree There's nothing wrong with 'pass by name' code parameters as such. Algol 60 used to do it as a matter of course, but guess why it was dropped? For the same reason that use strict 'refs' prohibits it. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: text replacement+
Kiko Uehara wrote: Hi everyone, Hello, I have a following data to analyze : - BlockA color 0 0 0 rcolor 1 1 1 dcolor 2 2 2 BloackB color 0 0 0 rcolor 1 1 1 dcolor 2 2 2 (...and so on) - I want to replace BlockA rcolor 1 1 1 to 4 4 4 and BlockB rcolor 1 1 1 to 0 0 0. I have variables like $BlockA_rcolor = rcolor 4 4 4. - while (IN) { if ( $_ =~ m/rcolor/ ) { $_ = $BlockA_rcolor; } print $_; } - Above code will replace all 'rcolor' lines in the data. Can anyone please give me an idea, what kind of method I could use ? If my question doesn't have enough information, please let me know. It looks like you should use paragraph mode and probably a hash: $/ = ''; my %rcolor = ( A = '4 4 4', B = '0 0 0' ); while ( IN ) { if ( /^\s+Block([A-Z])\b/ ) { my $key = $1; s/\b(rcolor\s+)\d+\s+\d+\s+\d+/$1$rcolor{$key}/; } print; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: text replacement+
On Nov 14, 2003, at 4:13 PM, James Edward Gray II wrote: my $block; while (IN) { if (/^(Block[A-Z]+)/) { $block = $1; } elsif (/^\s+([rd]?color)/) { my $color = $1; s/\d+ \d+ \d+$/$changes{${block}_$color}/ if exists $changes{${block}_$color}; } Oops, forgot the print() right here. Sorry. print; } James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Parsing for base domain
How about something like this (it's my first try, but it seems to work)... # use strict; use warnings; my @domains = qw(www.x.com x.com www.sandisk.com network.tv funny.co.jp johnson.pictures.geography.info); foreach(sort @domains){ if($_ =~ /([a-zA-Z0-9\-.]*?)([a-zA-Z0-9\-]+\.(co\.\w{2}|com|net|edu|gov|info|tv)) $/){ my $host = $1; my $domain = $2; $host = No host unless $host; print $host = $domain\n; }else{ print Error: domain name format incorrect!\n; } } # The regex gets a little convoluted, so I used YAPE::Regex::Explain to sort it out: The regular expression: (?-imsx:/([a-zA-Z0-9\-.]*?)([a-zA-Z0-9\-]+\.(co\.\w{2}|com|net|edu|gov|i nfo|tv))$/) matches as follows: NODE EXPLANATION -- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): -- /'/' -- (group and capture to \1: -- [a-zA-Z0-9\-.]*? any character of: 'a' to 'z', 'A' to 'Z', '0' to '9', '\-', '.' (0 or more times (matching the least amount possible)) -- )end of \1 -- (group and capture to \2: -- [a-zA-Z0-9\-]+ any character of: 'a' to 'z', 'A' to 'Z', '0' to '9', '\-' (1 or more times (matching the most amount possible)) -- \. '.' -- (group and capture to \3: -- co 'co' -- \. '.' -- \w{2}word characters (a-z, A-Z, 0-9, _) (2 times) -- |OR -- com 'com' -- |OR -- net 'net' -- |OR -- edu 'edu' -- |OR -- gov 'gov' -- |OR -- info 'info' -- |OR -- tv 'tv' -- )end of \3 -- )end of \2 -- $before an optional \n, and the end of the string -- /'/' -- )end of grouping -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: text replacement+
Kiko Uehara wrote: I have a following data to analyze : - BlockA color 0 0 0 rcolor 1 1 1 dcolor 2 2 2 BloackB color 0 0 0 rcolor 1 1 1 dcolor 2 2 2 (...and so on) - I want to replace BlockA rcolor 1 1 1 to 4 4 4 and BlockB rcolor 1 1 1 to 0 0 0. I have variables like $BlockA_rcolor = rcolor 4 4 4. - while (IN) { if ( $_ =~ m/rcolor/ ) { $_ = $BlockA_rcolor; } print $_; } - Above code will replace all 'rcolor' lines in the data. Can anyone please give me an idea, what kind of method I could use ? If my question doesn't have enough information, please let me know. Hi Kiko. Your description is a mixture of data and code. If you want us to look at your software then you need to post more than I have variables like $BlockA_rcolor = rcolor 4 4 4. But just from the identifiers in the data you have shown it looks like you need to alter a set of RGB values in a data file. If you have a clearer description of your source and your goal then we can help better. Are you changing a program that already exists, or are you writing from scratch? It's also usually better to show actual data if you can, rather than something that you think encapsulates the real thing. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Starting Perl
Randal L. Schwartz wrote: Rob == Rob Dixon [EMAIL PROTECTED] writes: Rob Perl programs conventionally go in *.pl files. No. Only on broken architectures that demand it (read: windows). On Unix, Perl programs have no extension, any more than cat has an extension. Why should the user care what the implementation language is? (sigh) Yomna el-Tawil wrote: Thank you all for ur answeres... But I've got some problems, i'd like to say first that i'm using activePerl , under windows. Randal L. Schwartz wrote: If you name your Perl program something.pl on a Unix machine, I shall continue to look at you quizzically until either you or I leave the room. :) Don't worry. I won't touch your Unix machine. (looking quizzically back) Rob Perl modules are in *.pm. Yes, this is enforced by Perl. Mm. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
OS Choices (was Starting Perl)
Randal L. Schwartz wrote: If you name your Perl program something.pl on a Unix machine, I shall continue to look at you quizzically until either you or I leave the room. :) Rob Dixon wrote: Don't worry. I won't touch your Unix machine. (looking quizzically back) To pass on an anonymous quote I once saw: Unix _is_ a user-friendly system it's just very picky about who its friends are. Thanks for making me smile on a Friday afternoon. Chris. (Unix user) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
An Alternative to Test::Harness was Re: external sub routine
On Friday, Nov 14, 2003, at 13:59 US/Pacific, Rajesh Dorairajan wrote: [..] All I want to do is: #Create a logger object and log a message using log4perl #call the function and check the $retval #if $retval == 1 $logger-info(Test succeded) #else $logger-warn( Test failed ) I've a bunch of such scenarios and I wish to have them in files like 0.t, 1.t, 2.t [..] As you can gather I am building a Test suite using Perl and would like to reuse mechanism used to test perl modules. In short I want to do something like: #main.pl #loop through MANIFEST and read contents into @tests #runtests from @tests #0.t sub test1 { my ( $foo ) = shift; #initialize logger object #call a function from module bar::somebar #if success log success #if failure log failure } The key requirement is that the .t files must capable of acquiring values from main.pl. Is this possible? This is an interesting approach, forgive me if I need a bit more information on how you are looking at the issues of what is being passed into your test harness. what I gather so far is that you have a directory with the basics in it Makefile.PL Somebar.pm MANIFEST t/ 0.t... Traditionally when I am doing static code coverage of that Somebar.pm { one should use at least one capital in the Module Name, since all lower case is reserved for pragma. } with the usual perl Makefile.PL make test Or when you are talking about testing a perl module is there some other context I am not seeing here I am thinking in terms of having named files in the t/ that deal with specific code cases, eg: t/exception.t would deal with checking the list of all of the 'exceptions' that it should be handled gracefully. This way I actually put all of the information in there that needs to be tested. IF I add a new function/method and need to check that it will manage all 'n' new exception cases I merely update that file with 'n' new specific cases. The files in the t/ directory then become the 'configuration' information as well as the executable. I'm not sure that I see what 'value' is added by trying to make those tests more 'dynamic' by reading from one file and passing in additional information to the test that will then test the Module in that directory. So my problem is less with the idea of using log4perl to provide additional logging than what exactly this 'testing harness' that is going to be in the 'main.plx' is suppose to be all about Hum... have you looked into say the libwww-perl where in the t/net section it has the neat tricks about having a require net/config.pl; that defines a set of global values that are common to the set of tests. { cf http://search.cpan.org/~gaas/libwww-perl-5.75/ } This allows the basic Test::Harness approach, and has a way that common values are available to the several different test cases. That might be a strategy that you will find worth investigating. ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Getting the best answer(WAS: RE: How do you dynamically assign array names?)
I think this touches on an issue that people should consider when they post to this list. Often people ask a question, and instead of asking for help with a problem, they ask How to do x, when x may not even be a solution to their problem (sorry if I'm singling you out, OP). When submitting a question to the list, try to answer these questions: What problem were you trying to solve? How did you try to solve it? What happened? What did you expect to happen? It's not just a matter of etiquette, it will get you better answers to your questions. -Original Message- From: Rob Dixon [mailto:[EMAIL PROTECTED] Sent: Friday, November 14, 2003 10:09 AM To: [EMAIL PROTECTED] Subject: Re: How do you dynamically assign array names? How can anyone suggest what the 'alternatives' may be without an explanation of the problem? Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Help with UNIX commands
I am researching some unix commands and I would like to know if someone knows where I can find them online. I just want to know what are they used for and if there are some available examples online.The commands are: snapshot and sdtprocess. Sorry if this is not the right place to post this. Thanks. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Parsing for base domain
On Friday, Nov 14, 2003, at 14:28 US/Pacific, Tim Johnson wrote: [..] use strict; use warnings; my @domains = qw(www.x.com x.com www.sandisk.com network.tv funny.co.jp johnson.pictures.geography.info); foreach(sort @domains){ if($_ =~ /([a-zA-Z0-9\-.]*?)([a-zA-Z0-9\- ]+\.(co\.\w{2}|com|net|edu|gov|info|tv)) $/){ my $host = $1; my $domain = $2; $host = No host unless $host; print $host = $domain\n; }else{ print Error: domain name format incorrect!\n; } } [..] My complements on both the code, and the fan out of the RE there. But there is this minor little problem, the fly in the ointment nas.nasa.gov it happens to BE the domain name - yes it is in the 'nasa.gov' name space - but it is it's own domain to which the 'host' component would be the www as in: www.nas.nasa.gov This is a part of the reason that trying to pick out the domain without getting into the actual DNS level gets to be a bit messy. keeping with just the nas.nasa.gov if you do the standard nslookup query you will find that it returns 198.9.9.7, but if you dig -x 198.9.9.7 you get an A Record for netra07.nas.nasa.gov - this is an old net hack by which the [EMAIL PROTECTED] would work the simplest - there would be a machine that actually could pick up and pass the smtp connection traffic... ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Capturing system call output value
On Friday, Nov 14, 2003, at 10:48 US/Pacific, [EMAIL PROTECTED] wrote: Thanks that help. but I notice there is a newline included in the variable when using the ($name)=`uname -n`; [..] See the Sys::Hostname module... http://danconia.org I of course like wiggins recommendation since the more traditional code solution is use Sys::Hostname; my $host = hostname; print we be $host \n; which will port over the various flavors and not lock you into needing to have 'uname' in your path. The other advantage is that you do not have to worry about the 'newline' since the Sys::Hostname module is your friend. My pet favorite way to deal with getting information in from external commands of course is open(CMD, $cmd 21 |) or die cmd $cmd failed with: $1; while(CMD) { # parse the command stuff here } close(CMD); Which is useful when the input you are expecting from $cmd is longer than a simple 'quicky'. ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
writing excel files
I need to be able to create Microsoft Excel files from a perl script. I want to know which module for doing this that people recommend. I don't need anything too fancy. There will be very little formatting. What formatting I need to do will be column widths and maybe bold and/or underline. I also need to be able to use formulas. Which module do people recommend? -- Andrew Gaffney -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help with UNIX commands
Mame Mbodji wrote: I am researching some unix commands and I would like to know if someone knows where I can find them online. I just want to know what are they used for and if there are some available examples online.The commands are: snapshot and sdtprocess. Sorry if this is not the right place to post this. Well it seems not to do with Perl, unless these tools are written in Perl, so it might be a little OTbut What variant of Unix? These are not tools that I have seen before, not that I am an all Unix guru. Have you tried the old stand by of: man snapshot man sdtprocess ??? That would be might first suggestion. If they are Perl then hopefully they have some form of internal documentation, try pulling them up in a text editor. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: writing excel files
On Nov 14, 2003, at 8:37 PM, Andrew Gaffney wrote: I need to be able to create Microsoft Excel files from a perl script. I want to know which module for doing this that people recommend. I don't need anything too fancy. There will be very little formatting. What formatting I need to do will be column widths and maybe bold and/or underline. I also need to be able to use formulas. Which module do people recommend? Spreadsheet::WriteExcel I use it regularly. It's good stuff. James -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Counting (easy!)
Steve Grazzini wrote: What do you think is happening under the hood for something like print for (0..0, 1, 2..5, func(6)..func(99)) I think the whole list would have to be generated. The optimization only applies to the case where there's just one range in place of the LIST. I agree. I'm not familiar with the ineternals of the language, but from a logical perspective, a range is a function, equivalent logically to the basic i++ C loop. There is absolutely no reason to generate a list for something that is so straigtforward in mathematical terms. The line above processes a logical list, where each discrete item has a very wide range of possiblities for its value. I find the Perl sytax a better match with the for or foreach in terms of expressing the desired functionality. The two posts we're discussing demonstrate how well the Perl syntax promotes natural language programming. The C-style syntax better demonstrates the difference between a list and a range: range; for (int i = 0; i 10; i++) list: for (ScalarArray * item = ARGV, i = 0; i item-count(); i++) Okay, I'm a little rusty on my C, and I don't know the precise implementations of range as opposed to list operations in Perl, but it seems pretty clear that there is a lot more processing required for any list, especially in an untyped language such as Perl, than for an integral range. I assume that Perl has some optimisations for lists that have only numeric values, but that is not something I would rely on. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Pivoting Data for use with gnuplot
Fellow perl coders, I am having trouble wrapping my head around how to accomplish the following: Given a dbi result set that consists of datetime, servername, databasename, procedurename and average elapsed time. Convert this into an data structure suitable for export to a file for use with gnuplot. The data is hourly and there may be gaps in the hours. The base problem is that I have to pivot the result sets so that for each unique occurrence of server/database/procedure I can associate the elapsed time to a reporting datetime. I think I understand what I have to feed gnuplot, ie. a file with a column for each server/database/procedure of elapsed times for each hour in the period. I believe that I want to make a hash of arrays, but I am confused as to how to pivot the data and accumulate/assign the arrays. Here is a sample of the test data that I am using, (the full set for one application for a two week period is over 15,000 rows) sql_result report_datetime server_name database_name procedure_name avg_elapsed 10/30/2003 1:00:00.000 PMBLOGSDB_D01A_SYBBlogData001 CommentEntry_Del0.0004 10/30/2003 3:00:00.000 PMBLOGSDB_D01A_SYBBlogData001 CommentEntry_Del0.0020 10/30/2003 4:00:00.000 PMBLOGSDB_D01A_SYBBlogData001 CommentEntry_Del0.0004 10/30/2003 9:00:00.000 PMBLOGSDB_D01A_SYBBlogData001 CommentEntry_Del0.0013 10/30/2003 12:00:00.000 PM BLOGSDB_D01A_SYBBlogData001 Comment_RtrByEntry0.0007 10/30/2003 1:00:00.000 PMBLOGSDB_D01A_SYBBlogData001 Comment_RtrByEntry0.0007 10/30/2003 2:00:00.000 PMBLOGSDB_D01A_SYBBlogData001 Comment_RtrByEntry0.0011 10/30/2003 3:00:00.000 PMBLOGSDB_D01A_SYBBlogData001 Comment_RtrByEntry0.0012 10/30/2003 4:00:00.000 PMBLOGSDB_D01A_SYBBlogData001 Comment_RtrByEntry0.0007 10/30/2003 2:00:00.000 PMBLOGSDB_D01A_SYBBlogData002 Comment_Rtr0.0008 10/30/2003 9:00:00.000 PMBLOGSDB_D01A_SYBBlogData002 Comment_Rtr0.0007 10/30/2003 10:00:00.000 PM BLOGSDB_D01A_SYBBlogData002 Comment_Rtr0.0006 10/30/2003 11:00:00.000 PM BLOGSDB_D01A_SYBBlogData002 Comment_Rtr0.0007 /sql_result What I am having difficulty with is how do I end up with : some_fancy_data_structure BLOGSDB_D01A_SYB BLOGSDB_D01A_SYB BLOGSDB_D01A_SYB BlogData001BlogData001 BlogData002 report_datetime CommentEntry_Del Comment_RtrByEntry Comment_Rtr 10/30/2003 12:00:00.000 PM 0.0013 0.0007 under 10/30/2003 1:00:00.000 PM0.0004 0.0007 under 10/30/2003 2:00:00.000 PMundef 0.0011 0.0008 10/30/2003 3:00:00.000 PM0.0020 0.0012 under 10/30/2003 4:00:00.000 PM0.0004 0.0007 under 10/30/2003 9:00:00.000 PMundef undef0.0007 10/30/2003 10:00:00.000 PM undef undef0.0006 10/30/2003 11:00:00.000 PM undef undef0.0007 /some_fancy_data_structure Ultimately, I am writing the above structure to a file so that I can take advantage of gnuplot (wish I had the luxury of GD or Chart, but system calls will have to do). I think I have to parse the data twice, once to determine the names of all the nodes and then again to populate each node. Is there a single pass solution ? groveling Thanks in advance, this is a wonderful list, I have over 500 tips saved for the 3 or 4 months that I have been listening in. /groveling Chuck Fox -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: writing excel files
James Edward Gray II wrote: On Nov 14, 2003, at 8:37 PM, Andrew Gaffney wrote: I need to be able to create Microsoft Excel files from a perl script. I want to know which module for doing this that people recommend. I don't need anything too fancy. There will be very little formatting. What formatting I need to do will be column widths and maybe bold and/or underline. I also need to be able to use formulas. Which module do people recommend? Spreadsheet::WriteExcel I use it regularly. It's good stuff. Nice. It looks like very good stuff. -- Andrew Gaffney -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help with UNIX commands
[EMAIL PROTECTED] wrote: I am researching some unix commands and I would like to know if someone knows where I can find them online. I just want to know what are they used for and if there are some available examples online.The commands are: snapshot and sdtprocess. Sorry if this is not the right place to post this. Thanks. The following link shows a huge list of OS level tasks and the commands to run them on a slew of different (*nix), including our favorites Solaris, HPUX and Linux. http://bhami.com/rosetta.html Enjoy Chuck -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: writing excel files
[EMAIL PROTECTED] wrote: I need to be able to create Microsoft Excel files from a perl script. I want to know which module for doing this that people recommend. I don't need anything too fancy. There will be very little formatting. What formatting I need to do will be column widths and maybe bold and/or underline. I also need to be able to use formulas. Which module do people recommend? Hi, I just wrote a script for use with Excel from a database. It writes a csv compliant file. My needs were simple for this particular file so I chose simple methods. I used the column list construct so that I could correctly order the output from the hash, that might be overkill, but I still needed the list of columns so that I could output them a column headers for the spreadsheet. There are modules out there that will give you a much broader range of features as well as an api to work with them. But for quick and dirty, this works fine. Regards, Chuck code sub DoWork { my( $pServer, $pUser, $pPassword, $pStartDate, $pEndDate ) = @_; my( $Query ); my( $Count, $Error, @Rows ); my( $Line ); my( @Record ); my( $statementHandle ); my( $data ); my( $output ); my( @ColumnList ); $Query =EOF; SELECT session_id, wr_promo_code, start_time = CONVERT( varchar(30), start_time, 109 ), end_time = CONVERT( varchar(30), end_time, 109 ), ip_address, browser_type, browser_version, user_agent, page_set_id, user_id, error_id FROM web_reg_sessions WHERE start_time = ? AND start_time ? EOF @ColumnList = ( session_id, wr_promo_code, start_time, end_time, ip_address, browser_type, browser_version, user_agent, page_set_id, user_id, error_id ); $Connection = DBI-connect( dbi:Sybase:server=$pServer;database=web_reg, $pUser, $pPassword ); $statementHandle = $Connection-prepare( $Query ) or die Count prepare statement: . $dbh-errstr; $statementHandle-execute( $pStartDate, $pEndDate ) or die Couldn't execute statement: . $statementHandle-errstr; print $OUT join( ,, @ColumnList ); print $OUT \n; while( $data = $statementHandle-fetchrow_hashref() ) { $output = ; foreach $column ( @ColumnList ) { if( $column eq start_time || $column eq end_time ) { $tmp = $data-{$column}; $tmp =~ s/ / /g; $tmp =~ s/ /-/g; $tmp =~ s/:000//; $output .= \ . $tmp . \,; } else { $output .= \ . $data-{$column} . \; $output .= , if $column ne $ColumnList[$#ColumList]; } } print $OUT $output\n; } $statementHandle-finish; } /code -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: writing excel files
Chuck Fox wrote: [EMAIL PROTECTED] wrote: I need to be able to create Microsoft Excel files from a perl script. I want to know which module for doing this that people recommend. I don't need anything too fancy. There will be very little formatting. What formatting I need to do will be column widths and maybe bold and/or underline. I also need to be able to use formulas. Which module do people recommend? Hi, I just wrote a script for use with Excel from a database. It writes a csv compliant file. My needs were simple for this particular file so I chose simple methods. I used the column list construct so that I could correctly order the output from the hash, that might be overkill, but I still needed the list of columns so that I could output them a column headers for the spreadsheet. There are modules out there that will give you a much broader range of features as well as an api to work with them. But for quick and dirty, this works fine. I considered just using CSV, but there are non-technical reasons why I didn't. If I write it to a file called something.csv, Excel can open it just fine and not complain. The problem is that the people who are going to be using these spreadsheets will be very confused when Excel starts popping up messages about converting to .xls format from CSV if they make changes, add formatting, etc. -- Andrew Gaffney -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: text replacement+
On Nov 15, Kiko Uehara said: - BlockA color 0 0 0 rcolor 1 1 1 dcolor 2 2 2 BloackB color 0 0 0 rcolor 1 1 1 dcolor 2 2 2 - BlockA rcolor 1 1 1 to 4 4 4 BlockB rcolor 1 1 1 to 0 0 0. I have variables like $BlockA_rcolor = rcolor 4 4 4. I would suggest a hash instead: $change{BlockA}{rcolor} = 4 4 4; $change{BlockB}{rcolor} = 0 0 0; or: %change = ( BlockA = { rcolor = 4 4 4, # other ones }, BlockB = { rcolor = 0 0 0, # other ones }, # other blocks ); while (IN) { if ( $_ =~ m/rcolor/ ) { $_ = $BlockA_rcolor; } print $_; } I'd suggest keeping track of what block you're in, and what attribute is on the line: BLOCK: while (IN) { # skip blank lines print, next if /^\s*$/; # otherwise extract the block name my ($block) = /^(\S+)/; # print the line print; # process the block's contents while (IN) { # restart the OUTER while loop if we're done with this block redo BLOCK unless /^\s+(\S+)/; # store the attribute my $attr = $1; # if this block has things to be modified, # and this attribute is one of them, change it if ($change{$block} and exists $change{$block}{$attr}) { s/\Q$attr\E.*/$attr $change{$block}{$attr}/; } # print the attribute print; } } Let me know if you understand it, or if you need more explanation. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]