RE: Some Advice plz :))
You are rude! dive the guy a break man! -Original Message- From: Pierre Smolarek [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 27, 2001 10:24 PM To: RDWest Sr.; [EMAIL PROTECTED] Subject: Re: Some Advice plz :)) e. you want us to do your work for you? /me points out that amazon has a large selection of very good perl books. - Original Message - From: RDWest Sr. [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, June 27, 2001 3:11 PM Subject: Some Advice plz :)) hi yall, yup, i'm an old country boy... loli'm strugling here to learn perl on my own and with help from(maybe yall)lol so plz bare with me... i need some advice on an issue here... i'm creating, well trying to create, a ranking system for my online pals... i've accomplished user signup, print info to flatfile database... send confirmation of account and a search for lost userid and pwd... now, i got to thinking... if say a user wants to update their info( change pwd, name, etc...)i'm just completely lost here... does anyone have a good explanation or some code snippets i can look at? tx again RD Sr. _ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com
CSS in Perl
Hi I'm in the process of developing an intranet which includes a site search engine. Having downloaded Perl scripts from the internet, I am now tweaking those scripts to fit in with the rest of the site. I have the initial search box embedded in an ASP page which on submission calls the Perl script in the cgi-bin. This script writes the html and displays the results. The ASP and HTML pages on the site use CSS, and I need to include the same styles on the page that returns the search results, to give the site consistency. Does anyone know of a way this can be accomplished, apart from rewriting the entire CSS in Perl, which is beyond my capabilities? Thanks Doug German [EMAIL PROTECTED]
RE: CSS in Perl
SNIP The ASP and HTML pages on the site use CSS, and I need to include the same styles on the page that returns the search results, to give the site consistency. Does anyone know of a way this can be accomplished, apart from rewriting the entire CSS in Perl, which is beyond my capabilities? you don't need to rewrite the style sheet, only apply existing tags from the sheet that you will be using to appropriate elements in the page(s) you create. since you are creating the pages in Perl yourself, you can put the tags anywhere you want as a part of the creation process. just be sure to include the CSS attachment line in your created page. hth Al Hospers CamberSoft, Inc. alatcambersoftdotcom http://www.cambersoft.com A famous linguist once said: There is no language wherein a double positive can form a negative. YEAH, RIGHT
Re: the phantom file handle
On Fri, Jun 29, 2001 at 03:45:32PM +0100, Francesco Scaglioni wrote: : Hi : : And thanks again. : : Can anyone suggest why the following gives me an error of: : : 'no comma allowed after filehandle at /cgi-bin/filename line 13' : : Line 13 is the print header, start_html( etc etc one That is actually a byproduct from the following error: : #!/usr/bin/perl -w : # : # test script to query an mysql database via cgi and web interface : # developed as standalone and now for conversion to run as cgi : # - in hashes at the bottom is the functionning standalone version : # : use strict; : use DBI; : use CGI qw(standard); Should be: use CGI qw(:standard); : my ($sql, $dbh, $sth, $field1, $value1, $field2, $value2, @rows, $counter, $q); : : print header, start_html(test_query), h1(test_query); : : print p(If you want to query the database please fill in the form : below and press the Query button), print hr(); : : $q = CGI - new(); : if (param()) { : $field1 = param (field1); : $value1 = param (value1); : $field2 = param (field2); : $value2 = param (value2); : : print h2(OK so far); : : $dbh = DBI - connect (DBI:mysql:ami,fgs) || die $DBI::errstr; : $sql = qq{SELECT * FROM testami WHERE $field1 = '$value1' and $field2 = '$value2'}; : $sth = $dbh - prepare($sql); : $sth - execute(); : : $counter = 0; : : while (@rows = $sth - fetchrow_array()) { : $counter++; : $dbh - disconnect(); : } : print p(The toal number of matches was \$counter); : } : else { : print hr(); : print start_form(); : print p(What is the first field ? : , textfield (field1)); : print p(WHat is value for field one ? : , textfield (value1)); : print p(What is name of field2 ? : , textfield(field2)); : print p(What is value for field2 ? : , testfield(value2)); : print p(submit(Query), reset(Clear)); : print end_form(), hr(); : } : : print end_html(); : : : #!/usr/bin/perl -w : # : #use strict; : #use DBI; : #my ($sql, $dbh, $sth, $field1, $value1, $field2, $value2, @rows, $counter); : # : #print Enter the first fieldname (field1) : ; chomp ($field1 = ); : #print enter the value for field one (value1) : ; chomp ($value1 = ); : #print Enter the second fieldname (field2) : ; chomp ($field2 = ); : #print enter the value for field two (value2) : ; chomp ($value2 = ); : : #$dbh = DBI - connect (DBI:mysql:ami,fgs) || die $DBI::errstr; : #$sql = qq{SELECT * FROM testami WHERE $field1 = '$value1' and $field2 = '$value2'}; : #$sth = $dbh - prepare($sql); : #$sth - execute(); : #$counter = 0; : #while (@rows = $sth - fetchrow_array()) { : #$counter++; : #print @rows\n; : #}; : #print Number of records = $counter\n\n; : #$dbh - disconnect; : Casey West -- Shooting yourself in the foot with Prolog You attempt to shoot yourself in the foot, but the bullet, failing to find its mark, backtracks to the gun, which then explodes in your face.
Strange Behavior
I was wondering if someone could help me with the following code bit. It is acting strangely. if($ARGV[0] =~ m/^-l$|^-list$/i) { print What ports? (Press return after each port and CRTL-D when done.); chomp(@getem = ); print Who do you wanna hit, Homie? ; chomp($peer = ); foreach $item (@getem) { pointscan($item); } } else{ print $ARGV[0] bad flag. \-l|-list\ only good option\n; exit(0); } I am trying to take -l or -list as a command line argument, but it bombs out with this error when run. james@warbaby:~/perl ./sinner.pl -l What ports? (Press return after each port and CRTL-D when done.) Can't open -l: No such file or directory Who do you wanna hit, Homie? I understand that the @ARGV array if for processing files added on the command line, but I thought that you could use it to process flags as well. I mean, I have before, I've looked over some of my older code, and I just can't see what I am doing differently, or incorrectly. All help is very much appreciated. Thank you! -James -- -- James Kelty Sr. Unix Systems Administrator The Ashland Agency [EMAIL PROTECTED]
Re: Strange Behavior
On Fri, 29 Jun 2001, James Kelty wrote: I am trying to take -l or -list as a command line argument, but it bombs out with this error when run. Perl, by default, will treat a command-line option as a file, so you also need to make sure you shift it off the @ARGV array if you are going to use it directly. In fact, the first thing you should do is shift out the @ARGV elements you want to use instead of using @ARGV elements directly, which you are doing. Better yet, take a look at Getopts::Std or Getopts::Long for a very clean way of using command-line switches. -- Brett http://www.chapelperilous.net/btfwk/ Some men feel that the only thing they owe the woman who marries them is a grudge. -- Helen Rowland
Re: Inheritance of package global variables
[inherited attributes] [get/set accessor methods] [regex validation of set] [better way?] I'm not sure about there being a *better* way, but I'm sure there are a lot of *other* ways. Various thoughts... Perl has the concept of tied data items. The basic operations on those data items, like setting the value, are done via arbitrary procedures you write. I can see one implementing what you describe, as a tied hash. To see a little more of what people have done with tie's in general: http://search.cpan.org/search?mode=modulequery=tie Of course, there may be other tied hash implementations not on cpan. If you don't have Damian Conway's book, get it. You might be interested in considering how CLOS (common lisp object system) notions relate to what you are doing. With CLOS, firing a method (which could be an Accessor method), meant the method dispatcher first looked to see if any Before methods matched the argument signature. If so, it fired the matching Before method(s). Those Before methods could then modify the dispatch process, eg abort the dispatch. At least, this is how it worked when I last looked at CLOS, about 10 years ago. This is a very general framework with what you are doing being one of many things that are naturally expressed using it. You could have a Before method that validates the argument to an Accessor method against a regex, and accepts/aborts the dispatch. But to get this to work with Perl, you'd have to play with the guts of method dispatch, something I would guess is a relatively non-trivial undertaking.
Re: background processing (again?)
this is what i understand from your mail. you need your main code to keep running, while servicing I/O from the netstat FH (or for that matter, any FH). Michael has already suggested pre packaged options, that should be able to help you out. however if you want to roll out your own code available options are 1) use a separate thread/process blocked on select. 2) a) use asynchronous I/O (signal driven) (SIGPOLL or SIGIO for SYSV or BSD) the handler could just set a flag, and the main loop (if there is any) could check and read data from the filehandle. if that is the case set the FH to non/blocking. b) if you want to transfer the data from the handler itself, use the barest minimum code in the handler and block the signal, when handling the shared data structure from the main loop. the drawback in the second option is that there is only one signal per process. so the OS cannot indicate which FH is ready to be read/written. however most modern signal facilities in *nix pass extra information about the signals. read up on sigaction in the solaris manuals to see if there is some other information passed to you process. another problem is if perl on your box, supports SIGPOLL. /kk On Thu, Jun 28, 2001 at 10:51:33PM -0400, Ronald J. Yacketta wrote: I have heard doing it this way will cause grief.. need blocking i/o or something along that lines. Also, I head that the flow of the program would _stop_ when reading the data... are there any other solutions? Ron P.S. kk, I never did get you example code working under Solaris, it works fine under Linux -Original Message- From: David M. Lloyd [mailto:[EMAIL PROTECTED]] Sent: June 28, 2001 09:55 To: Ronald J. Yacketta Cc: Perl Subject: Re: background processing (again?) On Thu, 28 Jun 2001, Ronald J. Yacketta wrote: Folks, to make a long story short I have a req to-do the following. 1) gather continues data from netstat -I hme0 $SLEEPTIME $netstatTMPFILE while still parsing other information/data etc.. that is, the script needs to be bale to collect the netstat data while it is running other process, not just fork netstat and wait for it to die/return. it will never die/return unless it is killed. Try something like this: open NETSTAT, netstat -I hme0 $SLEEPTIME | or die Can't start netstat: $!\n; Then, just read from the NETSTAT file handle. For more information, look at 'open' and 'sysopen' in the Camel book. Also, you may want to consider using 'select' if you don't want to block on reads. (Be sure you look at the 'ready file descriptors' version of 'select'). - D [EMAIL PROTECTED]
Re: Fork (not the kind you eat with)
Small problem with the below code how can you control the MAX amount of children you have? - Original Message - From: Chas Owens [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, June 28, 2001 7:07 PM Subject: Re: Fork (not the kind you eat with) A parent can fork as many times as it wants to (for that matter a child could fork as well). So your code would look like this: $SIG{CHLD} = IGNORE; #works on unix platforms, auto reaps children foreach $machine (get_machines()) { $pid = fork; if ($pid == 0) { #I am a child check_machine($machine); } elsif (not $pid) { #if parent then $pid = process id, if error then #$pid = undef error(); } } On 28 Jun 2001 17:03:39 +0100, Pierre Smolarek wrote: The one thing in perl that gets my head all confused is fork. Can someone point me in the right direction (be it book, website, or kind enough to offer code). I need to make a script that has to check 16000 servers in around 6 minutes. My rough maths works out that 44 checks a second are needed. Each server check takes about 0.5 seconds to return, so the best bet is to fork each individual check, the result of which gets added to mysql so no need to have a conversation going on between child and parent. Idealy i would like to control the max amount children i have to, say, around 50. Any help would be greatful. (I have the cook book open but only seems to talk about a single parent child pair..?!) Pierre. -- Today is Prickle-Prickle, the 33rd day of Confusion in the YOLD 3167 Keep the Lasagna flying!
Idea.. OCR in perl?
Does anyone know if there is either a c app that will take an image and ocr it ? (Character recognition) That would be cool as you could develop some nice apps with that in perl. Pierre
Re: :Telnet
Hi Vrunda, Can you post the script that responds to the CGI request? How are you passign the parameters from the CGI bit to the telnet bit? You say that it times out waiting for the input of the username and password. This is the bit that confuses me. Gary On Thursday 28 June 2001 6:13 pm, Prabhu, Vrunda P (UMC-Student) wrote: Thanks Gary, Here are some of the answers: I have a simple script (code follows) that when I run at the prompt, lists the files in the directory as it is supposed to. Next, rather than programmatically including the username and password, I wrote an HTML form that requests the two, and then calls a CGI that parses username and password, which then (I expect) should do exactly what the script below is doing. However, when I enter the username and password and press the SUbmit button, I get internal server error. ** #!/usr/bin/perl use Net::Telnet (); $ip = '...'; $username='...'; $password='...'; $t=new Net::Telnet(Prompt='/\[.*\]\$ $/'); $t-open($ip); $t-login($username, $password); @files=$t-cmd(ls -alg); print @files; $t-close; Hi Vrunda, I can't see why wrapping a CGI around your script should introduce a timeout. Presumably other CGI's work fine, and if you run the original command line one it still works? Does the command line one run in the same user ID and on the same server? Other CGI's work fine. If I try to run the modified CGI at the command prompt, it times out because it is waiting for the input of username and password. How are you detecting the timeout, is it being detected by your code, or is the script just dieing? Have you put some debugging info into the server error logs? How can I do that? NO, right now there is no debugging info. If so, what do they say? Hope these questions help, if not get back to the list with some more details. Gary On Wednesday 27 June 2001 7:57 pm, Vrunda Prabhu wrote: Thanks Gary, I got back to my work yesterday, and modified th eport number, spent a long time getting the prompt to work, but now can make a connection. Question: If I run the program at the command prompt and ask for a listing of files in the directory for example, it does that. In this code however, I have entered the username and password, and want to avoid this situation. So I wrote a HTML form that the user could enter his/her name and password, and this form would call the cgi, and proceed as before. HOwever, as soon as I do this, I run into a timeout error again. Can this be rectified easily? Thanks for any help in advance. Vrunda On Mon, 25 Jun 2001, Gary Stainburn wrote: Hi Vrunda, I've just re-read the message and noticed you're trying to use the POP protocol. To do that you need to use port 110. Before trying to do it with your script tho', try doing it directly by calling the telnet program. If that doesn't work, your script won't stand a chance. For a full list of ports and services look at the services file on your box (/etc/services on most unix systems \windows\services under windows. Gary On Friday 22 June 2001 4:39 pm, Prabhu, Vrunda P (UMC-Student) wrote: Gary: I used port 23 with the same outcome: read timed out. John Edwards (thanks very much John) suggested a document at : http://www.perlfect.com/articles/telnet.shtml which seems to be pretty good, an dmight have solutions. Vrunda -Original Message- From: Gary Stainburn To: Prabhu, Vrunda P (UMC-Student); '[EMAIL PROTECTED] ' Sent: 6/22/01 10:31 AM Subject: Re: :Telnet Hi, why are you telnetting to port 80? That's the http port. To use telnet, use port 23, which I think is the default anyway. Gary On Friday 22 June 2001 4:07 pm, Prabhu, Vrunda P (UMC-Student) wrote: I too have questions on the same topic - Net::Telnet. I tried the following code: (I have deleted the hostname, username and passwd), and get the error: read timed-out at ./teltry.cgi line 13 #!/usr/bin/perl my ($hostname, $line, $passwd, $pop, $username); $hostname=...; $username=...; $passwd=...; use Net::Telnet (); $pop=new Net::Telnet (Telnetmode = 0); $pop-open(Host = $hostname, Port =80); $line= $pop-getline; die $line unless $line=~/^\+OK/; $pop-print(user $username); $line = $pop-getline; die $line unless $line =~/^\+OK/; $pop-print(pass $passwd); $line=$pop-getline; Thanks in advance for any and all suggestions. My aim is to be able to telnet to a site, and once there work allow the user to work at the site, till the time when the user might wish to telnet to another site. If the second site is connected to the
function
Hi all I am brand new to programming and perl .I am having difficulty using functions.The perldoc is very vague and i do not know in which context to use function for example. i have an array @users=(ishmail,wendell) I need to use the getlogin function andi just cannot get the right syntax Your help will be appreciated. Khalil -Original Message- From: Pierre Smolarek [mailto:[EMAIL PROTECTED]] Sent: Thursday, June 28, 2001 6:04 PM To: [EMAIL PROTECTED] Subject: Fork (not the kind you eat with) The one thing in perl that gets my head all confused is fork. Can someone point me in the right direction (be it book, website, or kind enough to offer code). I need to make a script that has to check 16000 servers in around 6 minutes. My rough maths works out that 44 checks a second are needed. Each server check takes about 0.5 seconds to return, so the best bet is to fork each individual check, the result of which gets added to mysql so no need to have a conversation going on between child and parent. Idealy i would like to control the max amount children i have to, say, around 50. Any help would be greatful. (I have the cook book open but only seems to talk about a single parent child pair..?!) Pierre.
Taint checking with -T
When I added -T to an existing Perl script, I got the error message: Too late for -T option at main.cgi line 1. Is this a common error message with -T? What am I doing wrong? You can get the source at: http://www.redsquirreldesign.com/soapbox = Dave Hoover Twice blessed is help unlooked for. --Tolkien http://www.redsquirreldesign.com/dave __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
Re: Taint checking with -T
On Fri, 29 Jun 2001, dave hoover [EMAIL PROTECTED] wrote, When I added -T to an existing Perl script, I got the error message: Too late for -T option at main.cgi line 1. Is this a common error message with -T? What am I doing wrong? Usually yes, when you invoke the script from the command line like, perl main.cgi To avoid the message, you have to supply the -T switch directly, perl -T main.cgi Or, if you're in the unix environment, ./main.cgi provided that the script has appropriate mode. You can find the explanation about the message in 'perldiag' manual page by issueing, perldoc perldiag and search the relevant string. hth; __END__ -- s::a::n-http(www.trabas.com)
Re: confusing Perl idioms and practices
At 11:01 28.06.2001 -0700, Peter Scott wrote: Readable is like obscene (in more ways than one, in some code I've seen). I spent a little time in my book (one day I hope to have to say which book :-) going over pros and cons of different takes on this. But as it stands, readable is simply meaningless, and guaranteed to cause friction. Your elaboration doesn't help either. Readable is only meaningful in a context of how the code is going to be used and what your tactical and strategic goals are. Debating it in a virtual vacuum like this is what I call a pinhead discusssion - how many angels can dance on the head of a pin... If you define readable as simple enough for the extreme beginner to understand, I agree. This is not only obscene, it also makes it impossible to take full advantage of the language, as some constructs are necessarily complicated, and require a firm understanding of Perl to decipher. However, I think a general level of non-obfuscation can be reached. When working in groups, it becomes a necessity. It's a matter of finding a common style in the group. This saves time when someone is on vacation and you have to fix a bug in their code. If they go around naming variables $x and $y instead of $names and $sizes (or, even better, $raNames and $raSizes), you spend a lot of time just figuring out what's going on. Many will argue (correctly) that no decent programmer would name his or her variables $x and $y outside of a for loop. However, rejecting readability out of hand as catering to beginners leads to similar behavior. I always prefer an extra line of code in the spirit of readability. If nothing else, it saves me from getting phone calls when I should be laying on the beach :) Aaron Craig Programming iSoftitler.com
Re: Matching strings
Observe, ye doubter: $ perl -le '@vars = qw(one two three two); @h{@vars} - (); print Duplicate in (@vars) unless keys %h == @vars; @vars = qw(one two three four); @hh{@vars} = (); print Duplicate unless keys %hh == @vars' Duplicate in (one two three two) $ Because.. what do we know about hash keys? They must be... *prompt* *prompt* Ah-ha! I stand corrected (and informed). Thank you, oh wise one. -T
short filehandle question
Hi, Executing my program with -w option I get the following warning: 'Value of HANDLE construct can be 0; test with defined() at readData line 65535.' Surely I do not have 65535 lines in my program, but I suspect this one: #reading data open (FILEH, $filename) or die Can't open file!\n; while ($line = FILEH) { How should I rewrite it to avoid that warning? Thanks in advance, Ela
Re: function
On 29 Jun 2001 11:31:51 +0200, BHEEKOO,KHALIL (HP-SouthAfrica,ex1) wrote: Hi all I am brand new to programming and perl .I am having difficulty using functions.The perldoc is very vague and i do not know in which context to use function for example. i have an array @users=(ishmail,wendell) I need to use the getlogin function andi just cannot get the right syntax Your help will be appreciated. Khalil snip reason=irrelevent / Why do you think you need getlogin? Getlogin does not accept any arguments and returns the name of the currently logged in user. Are you looking for the uids of the users in @users? If so then use a foreach loop like this: foreach $name (@users) { print $name has uid , getpwnam($name), \n; } -- Today is Setting Orange, the 34th day of Confusion in the YOLD 3167 All Hail Discordia!
RE: Modules question
put use (MODULE NAME); at the top of the script. Run the script and see if it generates an error. e.g use Win32::Lanman; -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: 29 June 2001 13:36 To: [EMAIL PROTECTED] Subject: Modules question Help with Modules please. Is there a option I can run with perl to find out if a particular module is installed? Thanks, Anna --Confidentiality--. This E-mail is confidential. It should not be read, copied, disclosed or used by any person other than the intended recipient. Unauthorised use, disclosure or copying by whatever medium is strictly prohibited and may be unlawful. If you have received this E-mail in error please contact the sender immediately and delete the E-mail from your system.
Re: Modules question
Hi Anna, To find out all the modules installed on your system, refer to the following URL: http:[EMAIL PROTECTED]/msg04057.html To find out about a single one, you can do: perl -MMODULE_NAME -e 1 So, to see if CGI.pm is installed: perl -MCGI -e 1 If you see no error messages, it is installed, if you do.. it isn't. Cheers, Kevin On Fri, Jun 29, 2001 at 08:35:34AM -0400, [EMAIL PROTECTED] ([EMAIL PROTECTED]) spew-ed forth: Help with Modules please. Is there a option I can run with perl to find out if a particular module is installed? -- [Writing CGI Applications with Perl - http://perlcgi-book.com] Don't mind your make-up, you'd better make your mind up. -- Frank Zappa
Re: function
On 29 Jun 2001, Chas Owens [EMAIL PROTECTED] wrote, On 29 Jun 2001 11:31:51 +0200, BHEEKOO,KHALIL (HP-SouthAfrica,ex1) wrote: Hi all Why do you think you need getlogin? Getlogin does not accept any arguments and returns the name of the currently logged in user. Are you looking for the uids of the users in @users? If so then use a foreach loop like this: foreach $name (@users) { print $name has uid , getpwnam($name), \n; } Beware, print takes LIST argument. That way, you invoke getpwnam in *list* context. It only returns UID in *scalar* context. print $name has uid , scalar getpwnam $name, \n; or, my $uid = getpwnam $name; print $name has uid $uid\n; __END__ -- s::a::n-http(www.trabas.com)
Re: Fork (not the kind you eat with)
On 29 Jun 2001 09:52:16 +0100, Pierre Smolarek wrote: Small problem with the below code how can you control the MAX amount of children you have? snip / Well, that is harder. One way (and there are probably better ones) would be to work with many subsets of the machines getting the pids for each set and then waiting for them [the children] to finish before forking off more. NOTE: This code has not been tested; there may be typos or logic bugs in it. code use constant MAX = 10; my @machines = get_machines(); while (@machines) { #while there are still machines left my @pids; foreach my $machine (splice(@machines, 0, MAX)) { push @pids, fork; if ($pids[-1] == 0) { #I am a child check_machine($machine); } elsif (not $pids[-1]) { #if parent then $pid = process id, if error then #$pids[-1] = undef pop @pids; #get rid of the undef error(); } } #reap the children foreach my $pid (@pids) { waitpid $pid, 0; #wait for each fork to finish } } /code -- Today is Setting Orange, the 34th day of Confusion in the YOLD 3167 All Hail Discordia!
Optional Variables
What's the proper syntax to indicate that a variable is optional? The script that I have created works great when I pass in a variable, but the script need to execute the SQL even if I don't pass in a variable. Thanks, Kim
Re: function
On 29 Jun 2001 20:08:05 +0700, Hasanuddin Tamir wrote: On 29 Jun 2001, Chas Owens [EMAIL PROTECTED] wrote, On 29 Jun 2001 11:31:51 +0200, BHEEKOO,KHALIL (HP-SouthAfrica,ex1) wrote: Hi all Why do you think you need getlogin? Getlogin does not accept any arguments and returns the name of the currently logged in user. Are you looking for the uids of the users in @users? If so then use a foreach loop like this: foreach $name (@users) { print $name has uid , getpwnam($name), \n; } Beware, print takes LIST argument. That way, you invoke getpwnam in *list* context. It only returns UID in *scalar* context. print $name has uid , scalar getpwnam $name, \n; or, my $uid = getpwnam $name; print $name has uid $uid\n; __END__ -- s::a::n-http(www.trabas.com) Oops, I hate typos. The example was meant to be foreach $name (@users) { print $name has uid . getpwnam($name) . \n; } The concat operators (.) would have forced getpwnam into scalar context. -- Today is Setting Orange, the 34th day of Confusion in the YOLD 3167 Wibble.
Re: Modules question
On Fri, 29 Jun 2001 [EMAIL PROTECTED] wrote: Help with Modules please. Is there a option I can run with perl to find out if a particular module is installed? Try perl -MModuleName -e ''. If it isn't in @INC, you'll get an error, otherwise it will return to the command-line prompt. -- Brett http://www.chapelperilous.net/btfwk/ Q: How do you play religious roulette? A: You stand around in a circle and blaspheme and see who gets struck by lightning first.
Re: Optional Variables
On Fri, 29 Jun 2001, Kim Green wrote: What's the proper syntax to indicate that a variable is optional? The script that I have created works great when I pass in a variable, but the script need to execute the SQL even if I don't pass in a variable. You can set a sane default for the variable: my $option = $ARGV[0] || 1; If $ARGV[0] is not defined, then $option will be 1. Or you create your program logic accordingly to do one thing if the option is defined and another thing is if isn't defined. -- Brett http://www.chapelperilous.net/btfwk/ I B M U B M We all B M For I B M -- H.A.R.L.I.E.
RE: trailing newline
Name HexASCII ---- LineFeed %0a0010 Carriage Return %0d0013 I think this is what your after... good luck. -Original Message- From: Stéphane JEAN BAPTISTE [mailto:[EMAIL PROTECTED]] Sent: 29 June 2001 14:22 To: PERL Subject: trailing newline Hi I need the (hexa?) code for trailing newline, but not \n. I need a code like (#233 or eacute for é) tks
Re: trailing newline
On 29 Jun 2001 15:21:46 +0200, Stéphane JEAN BAPTISTE wrote: Hi I need the (hexa?) code for trailing newline, but not \n. I need a code like (#233 or eacute for é) tks For HTML a newline is generated by the br tag. I am not certain what would happen if you put #10; (the LF character) or #13;#10; (the CRLF pair) in an HTML doc, but I would assume it would treat them like it does the characters themselves. NOTE: the values of LF and CR above are in decimal the hex values are 0x0A and 0x0D respectivly. In octal they are 012 (LF) and 015 (CR). -- Today is Setting Orange, the 34th day of Confusion in the YOLD 3167 Frink!
How do I copy a tape from one drive to another ?
Hi all, Assuming I have a computer with two identical tape drives, I want to copy the contents of a tape from one unit to the other. This should work under Windows NT Server. I know that under Unix I could use dd, but is there a way I can have access to the Windows tape device from Perl, in order to write a script which duplicates the tape contents? Thank you, Adrian Ichim Network administrator, Timken Romania phone: +(40) 44 403172 e-mail: [EMAIL PROTECTED]
Re: Optional Variables
On 29 Jun 2001, Chas Owens wrote: In cases where you expect 0 to be a valid value it may be better to use this construct: $var = defined($ARGV[0]) ? $ARGV[0] : DEFAULT; Thanks for pointing that out. That is a more robust way of doing that. -- Brett http://www.chapelperilous.net/btfwk/ Just because he's dead is no reason to lay off work.
AW: short filehandle question
Hi, It is declared as my $FILEH at the beginning of the file... Could you tell me what the difference is? Ela -Ursprüngliche Nachricht- Von: Jerry Preston [mailto:[EMAIL PROTECTED]] Gesendet: Freitag, 29. Juni 2001 15:39 An: Ela Jarecka Betreff: Re: short filehandle question Ela, You need to declare FILEH: local( *FILEH ); Jerry Ela Jarecka wrote: Hi, Executing my program with -w option I get the following warning: 'Value of HANDLE construct can be 0; test with defined() at readData line 65535.' Surely I do not have 65535 lines in my program, but I suspect this one: #reading data open (FILEH, $filename) or die Can't open file!\n; while ($line = FILEH) { How should I rewrite it to avoid that warning? Thanks in advance, Ela
Re: Optional Variables
Chas == Chas Owens [EMAIL PROTECTED] writes: Chas In cases where you expect 0 to be a valid value it may be better to use Chas this construct: Chas $var = defined($ARGV[0]) ? $ARGV[0] : DEFAULT; I prefer the sensible: $var = @ARGV ? shift : DEFAULT; Why test defined when you know the length of the array? -- 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!
is this a structure of some kind?
sorry to ask such a simple question, but i can't find reference to this syntax in a couple of my Perl reference books (i think it's time i bought the Camel book) -- ALL_SESSIONS: foreach $session_dir (@ARGV) { @studies = `ls -1 $session_dir `; @session_path = split /\//, $session_dir ; $session = $session_path[$#session_path] ; print \n Checking $session: ; ALL_STUDIES: foreach $study (@studies) { chomp $study; $numfound = 0; @hits = (); # new list -- the items in CAPS: are some kind of structure, right? i just haven't seen the CAPS: notation yet. thanks.
Re: data matching
Michael Fowler [EMAIL PROTECTED] wrote: You probably shouldn't be using a bare block as a looping construct. What is the intent of your code, what do you want it to do if $street eq 'MAIN' or $street ne 'MAIN'? Sorry I have not been quite clear about what I want to get: use strict; my %state = ( CHICAGO = [qw(MAIN BROADWAYOAK)], LA = [qw(DELTAGAMMA )], BOSTON = [qw(FIRSTMAIN )], BURLINGTON = [qw(SECOND ONE)], SEATTLE = [qw(GREATMAIN )], ); CITY:while (my $line = DATA){ my @line = split /\s*,\s*/, $line; my $city = $line[3]; foreach my $city (keys %state) { foreach my $street (@{ $state{$city} } ){ if ($street ne 'MAIN'){ next ; } } next CITY; } print $line\n; } __DATA__ STATE ,IL, SDW,CHICAGO STATE,CA, SFD,LA STATE, MA, FDR,BOSTON STATE, CT,FGD,BURLINGTON STATE, WA, SDF,SEATTLE __END__ I want my output to be (print only lines where city/ street 'MAIN' : STATE ,IL, SDW,CHICAGO STATE, MA, FDR,BOSTON STATE, WA, SDF,SEATTLE I.S __ Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/
Re: is this a structure of some kind?
ALL_CAPS: is a label that sets off a block of code. A more obvious use for it would be to emulate the switch structure in C++: SWITCH: { if($var == 1) { do something last SWITCH; # skip the rest of this block } if($var == 2) { do something else last SWITCH; # skip the rest of this block } do some default thing } basically, a string followed by a colon is a point in the code that you can tell the program to go to using keywords like next, last, etc. somewhere in your script, there must be a reference to ALL_SESSIONS and ALL_STUDIES -- hopefully not using the dreaded goto! :) At 09:10 29.06.2001 -0500, Humberto Varela wrote: sorry to ask such a simple question, but i can't find reference to this syntax in a couple of my Perl reference books (i think it's time i bought the Camel book) -- ALL_SESSIONS: foreach $session_dir (@ARGV) { @studies = `ls -1 $session_dir `; @session_path = split /\//, $session_dir ; $session = $session_path[$#session_path] ; print \n Checking $session: ; ALL_STUDIES: foreach $study (@studies) { chomp $study; $numfound = 0; @hits = (); # new list -- the items in CAPS: are some kind of structure, right? i just haven't seen the CAPS: notation yet. thanks. Aaron Craig Programming iSoftitler.com
help with running -T
Here is an ultra-simple script tst: --- #!/usr/bin/perl -w use Blah; $b = new Blah; print foo; $b-bar(); --- Here is the ultra simple module Blah.pm: package Blah; sub new { my $pkg = shift; bless {}; $pkg; } sub bar { print bar\n; } 1; -- Everything works fine: % perl tst foobar But when I add -T to the first line of tst, something goes wrong: % perl -T tst Can't locate Blah.pm in @INC (@INC contains: /usr/local/lib/perl5/sun4-solaris/5.00401 /usr/local/lib/perl5 /usr/local/lib/perl5/site_perl/sun4-solaris /usr/local/lib/perl5/site_perl) at tst line 3. BEGIN failed--compilation aborted at tst line 3. I can't figure out why this is happening. Can anyone help? = Dave Hoover Twice blessed is help unlooked for. --Tolkien http://www.redsquirreldesign.com/dave __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
Re: is this a structure of some kind - found it!
i found it. page 104 of Learning Perl, 2nd. sheesh... this is what happens when i'm only 1/2 cup of coffee into the morning. thanks all! -- On Friday, June 29, 2001 09:10, Humberto Varela [EMAIL PROTECTED] wrote: sorry to ask such a simple question, but i can't find reference to this syntax in a couple of my Perl reference books (i think it's time i bought the Camel book) -- ALL_SESSIONS: foreach $session_dir (@ARGV) { @studies = `ls -1 $session_dir `; @session_path = split /\//, $session_dir ; $session = $session_path[$#session_path] ; print \n Checking $session: ; ALL_STUDIES: foreach $study (@studies) { chomp $study; $numfound = 0; @hits = (); # new list -- the items in CAPS: are some kind of structure, right? i just haven't seen the CAPS: notation yet. thanks.
Re: is this a structure of some kind?
Labels are very useful for breaking out of nested loops: LOOP1: while (condition1) { LOOP2 while (condition2) { last LOOP1 if (fatal error); } } On 29 Jun 2001 16:17:54 +0200, Aaron Craig wrote: ALL_CAPS: is a label that sets off a block of code. A more obvious use for it would be to emulate the switch structure in C++: SWITCH: { if($var == 1) { do something last SWITCH; # skip the rest of this block } if($var == 2) { do something else last SWITCH; # skip the rest of this block } do some default thing } basically, a string followed by a colon is a point in the code that you can tell the program to go to using keywords like next, last, etc. somewhere in your script, there must be a reference to ALL_SESSIONS and ALL_STUDIES -- hopefully not using the dreaded goto! :) At 09:10 29.06.2001 -0500, Humberto Varela wrote: sorry to ask such a simple question, but i can't find reference to this syntax in a couple of my Perl reference books (i think it's time i bought the Camel book) -- ALL_SESSIONS: foreach $session_dir (@ARGV) { @studies = `ls -1 $session_dir `; @session_path = split /\//, $session_dir ; $session = $session_path[$#session_path] ; print \n Checking $session: ; ALL_STUDIES: foreach $study (@studies) { chomp $study; $numfound = 0; @hits = (); # new list -- the items in CAPS: are some kind of structure, right? i just haven't seen the CAPS: notation yet. thanks. Aaron Craig Programming iSoftitler.com -- Today is Setting Orange, the 34th day of Confusion in the YOLD 3167 Fnord.
Re: AW: short filehandle question
Ela, The * is a typeglob that are still used for passing or storing filehandles. Using my is to the most frequently used form of lexically scoped declaration. You might look at scoped declarations. Jerry Ela Jarecka wrote: Hi, It is declared as my $FILEH at the beginning of the file... Could you tell me what the difference is? Ela -Ursprüngliche Nachricht- Von: Jerry Preston [mailto:[EMAIL PROTECTED]] Gesendet: Freitag, 29. Juni 2001 15:39 An: Ela Jarecka Betreff: Re: short filehandle question Ela, You need to declare FILEH: local( *FILEH ); Jerry Ela Jarecka wrote: Hi, Executing my program with -w option I get the following warning: 'Value of HANDLE construct can be 0; test with defined() at readData line 65535.' Surely I do not have 65535 lines in my program, but I suspect this one: #reading data open (FILEH, $filename) or die Can't open file!\n; while ($line = FILEH) { How should I rewrite it to avoid that warning? Thanks in advance, Ela
Re: Modules question
On Win32, typing ppm verify at the command prompt will list all the modules installed on your system quit will exit the ppm tool [EMAIL PROTECTED] wrote: Help with Modules please. Is there a option I can run with perl to find out if a particular module is installed? Thanks, Anna
Re: AW: short filehandle question
--- Jerry Preston [EMAIL PROTECTED] wrote: The * is a typeglob that are still used for passing or storing filehandles. Using my is to the most frequently used form of lexically scoped declaration. You might look at scoped declarations. For most cases, I'd recommend using the FileHandle module. It returns flexible filehandles in simple scalars that can be easily passed around, recursed, stored in arrays, whatever. use FileHandle; my $fhIN = new FileHandle $inFile or die $inFile: $!; my $fhOUT = new FileHandle $outFile or die $outFile: $!; my $fhPIPE = new FileHandle ls -l|or die ls: $!; my $rec = $fhIN; my $line = $fhPIPE; print $fhOUT $rec; Paul = Ela Jarecka wrote: Hi, It is declared as my $FILEH at the beginning of the file... Could you tell me what the difference is? Ela -Ursprüngliche Nachricht- Von: Jerry Preston [mailto:[EMAIL PROTECTED]] Gesendet: Freitag, 29. Juni 2001 15:39 An: Ela Jarecka Betreff: Re: short filehandle question Ela, You need to declare FILEH: local( *FILEH ); Jerry Ela Jarecka wrote: Hi, Executing my program with -w option I get the following warning: 'Value of HANDLE construct can be 0; test with defined() at readData line 65535.' Surely I do not have 65535 lines in my program, but I suspect this one: #reading data open (FILEH, $filename) or die Can't open file!\n; while ($line = FILEH) { How should I rewrite it to avoid that warning? Thanks in advance, Ela __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
Re: trailing newline
This bit of code generates a file with all three types of new line in it open(TESTFILE, test.txt) or die Sorry, cannot open the test file; binmode(TESTFILE); print TESTFILE This is a DOS line ending\x0d\x0a; print TESTFILE This is a Mac line ending\x0d; print TESTFILE This is a Unix line ending\x0a; print TESTFILE This is a DOS line ending\x0d\x0a; print TESTFILE This is a Mac line ending\x0d; print TESTFILE This is a Unix line ending\x0a; print TESTFILE This is a DOS line ending\x0d\x0a; print TESTFILE This is a Mac line ending\x0d; print TESTFILE This is a Unix line ending\x0a; close TESTFILE; print The test file test.txt has been successfully written\n; Stéphane JEAN BAPTISTE wrote: Hi I need the (hexa?) code for trailing newline, but not \n. I need a code like (#233 or eacute for é) tks
RE: Invalid switch message
You could do this $returned = `spam -momittag -c $tooldir/nsgmls.cat $dtddir/$.dtd $file`; $returned will now contain whatever your program would have printed to the console. You can work with the data in a perl script, or just save it out using perl open OUT, $newfile or die Can't create $newfile: $!; print OUT $returned; close OUT; Then again, maybe it's just a case of escaping the , like so. system(spam -momittag -c $tooldir/nsgmls.cat $dtddir/$.dtd $file \$newfile); (not really an answer, just pointers...) John -Original Message- From: Keith Haynes [mailto:[EMAIL PROTECTED]] Sent: 29 June 2001 16:43 To: [EMAIL PROTECTED] Subject: Invalid switch message Hi all, I am relatively new to Perl and my background is not programming although I quite enjoy manipulating text using Perl, with this in mind I would appreciate any replies being kept relatively simple, if that's possible. My problem, I am running an exe file within perl and receiving the message 'invalid switch' when I use the redirect symbol () to output to a file, the script still performs the required operation but it would be nice to remove this message. There follows an example of the code I am using: system(spam -momittag -c $tooldir/nsgmls.cat $dtddir/$.dtd $file $newfile); Thanking you in advance, Keith --Confidentiality--. This E-mail is confidential. It should not be read, copied, disclosed or used by any person other than the intended recipient. Unauthorised use, disclosure or copying by whatever medium is strictly prohibited and may be unlawful. If you have received this E-mail in error please contact the sender immediately and delete the E-mail from your system.
FW: Win32 fork(), parent then child
Hi, I tested with a while loop. They do change after a while. This probably has to do with how the output is done on the same terminal in windows and how it handle timesharing. Fork does work correctly with my version of ActivePerl on Win32... -Robin -Original Message- From: Paul Murphy [SMTP:[EMAIL PROTECTED]] Sent: Friday, June 29, 2001 11:22 AM To: [EMAIL PROTECTED] Subject: Win32 fork(), parent then child Hey everyone: Anyone using fork() in Win32 ActivePerl? Consider the following code: code use FileHandle; STDOUT-autoflush(1); $kidpid = fork(); print pid = $$ kidpid = $kidpid\n; print pid = $$ kidpid = $kidpid\n; print pid = $$ kidpid = $kidpid\n; print pid = $$ kidpid = $kidpid\n; print pid = $$ kidpid = $kidpid\n; print pid = $$ kidpid = $kidpid\n; print pid = $$ kidpid = $kidpid\n; print pid = $$ kidpid = $kidpid\n; print pid = $$ kidpid = $kidpid\n; /code I would have thought that the child and parent output would be intermingled. But they don't, the child code gets executed after the parent code is complete. Which kinda defeats the purpose. I have even put in a while() after this that bails when I tell it. The child code gets executed once I let the parent process terminate, or at least the output arrives after the output of the first is complete. But I have stdout autoflushed. Am I missing something here? Paul. -- - CRESTCo Ltd. The views expressed above are not necessarily those 33 Cannon Street.held by CRESTCo Limited. London EC4M 5SB (UK) +44 (020) 7849 http://www.crestco.co.uk -- -
Re: data matching
On Fri, Jun 29, 2001 at 10:15:54AM -0400, F.H wrote: CITY:while (my $line = DATA){ my @line = split /\s*,\s*/, $line; my $city = $line[3]; foreach my $city (keys %state) { foreach my $street (@{ $state{$city} } ){ if ($street ne 'MAIN'){ next ; } } next CITY; } print $line\n; } Ok, those nexts cause this to do nothing; if the street does not equal main, you go to the next loop; after reaching the end of one loop, you go to the line (labeled, poorly, CITY). Look at my original code; you'll notice I print something if there is a MAIN street, and something if there isn't. If you don't want something printed if there isn't, remove the print statement, don't move the code around, don't relabel loops with poor names, and especially don't turn off use strict. Also, the read loop should be: while (defined(my $line = DATA)) { ... } I want my output to be (print only lines where city/ street 'MAIN' : STATE ,IL, SDW,CHICAGO STATE, MA, FDR,BOSTON STATE, WA, SDF,SEATTLE For this, you should make the following changes to your code: place the two foreach loops in my original code inside your while loop, remove the statement printing something when there is a 'MAIN' street, and change the statement printing something when there is no 'MAIN' street to print the data you want. Do you understand my code? Do you understand your own code? It sounds to me like you haven't quite gotten some of the Perl basics. What learning material do you have? Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com --
module install
When you install a perl module from CPAN should you do it as root???
System calls in perl for ps and netstat - less expensive way?
From PERL, I have been doing some system calls like this: (see * lines) * my $procentry=`ps -ef | grep -v grep | grep $self-{pid} `; chomp $procentry; $self-debug(1, Procentry: [$procentry]); if ($procentry =~ /\defunct\/ ) { $self-debug(1, --- closed ssh tunnel. Tunnel proc defunct); $tunnelok=0; } * my $nstat=`netstat -an | grep '127.0.0.1' `; chomp $nstat; $self-debug(1, NStat: [$nstat]); if (!$nstat) { $self-debug(1, --- closed ssh tunnel. Netstat result empty); $tunnelok=0; } Is this really computationally expensive? (I already know this makes my code not portable) Im not calling these very often, is there a better way to do this? thanks, Matt
RE: background processing (again?)
Maybe I just don't understand.. but wont there _always_ be data to read from netstat? to me, it seems as tho the loop _not_ work as intended, it would always pass the can_read and read data from netstat and never parse the other code? Regards, Ron -Original Message- From: David M. Lloyd [mailto:[EMAIL PROTECTED]] Sent: June 29, 2001 10:37 To: Ronald J. Yacketta Cc: Perl Subject: RE: background processing (again?) On Thu, 28 Jun 2001, Ronald J. Yacketta wrote: I have heard doing it this way will cause grief.. need blocking i/o or something along that lines. Also, I head that the flow of the program would _stop_ when reading the data... are there any other solutions? You can get around blocking I/O by using the IO::Select module: ### PERL open NETSTAT, netstat -I hme0 $SLEEPTIME | or die Can't start netstat: $!\n; my $select = new IO::Select; $select-add_reader(\*NETSTAT); while (1) { if ($select-can_read(0)) { # There is data so read it } else { # do something else while we wait } } ### END PERL P.S. kk, I never did get you example code working under Solaris, it works fine under Linux If you're talking about my code, be aware that 'netstat' takes different arguments based on which platform you're on. - D [EMAIL PROTECTED]
Re: module install
On Fri, Jun 29, 2001 at 11:31:28AM -0500, Hal Wigoda wrote: When you install a perl module from CPAN should you do it as root??? That's the easiest way to do it. Another possibility is to install somewhere else on the file system, not in the system site_perl directory. That other directory should be found in @INC when using those modules. Alternatively, you could open up the site_perl hierarchy so that ordinary users can add modules to it, but that's a very bad idea. Z.
RE: System calls in perl for ps and netstat - lessexpensive way?
Hi Matt Can you describe a little bit what U are trying to do or include more of the code. Depending on what U are trying to do, there may be less expensive alternatives Thanks Jim From PERL, I have been doing some system calls like this: (see * lines) * my $procentry=`ps -ef | grep -v grep | grep $self-{pid} `; chomp $procentry; $self-debug(1, Procentry: [$procentry]); if ($procentry =~ /\defunct\/ ) { $self-debug(1, --- closed ssh tunnel. Tunnel proc defunct); $tunnelok=0; } * my $nstat=`netstat -an | grep '127.0.0.1' `; chomp $nstat; $self-debug(1, NStat: [$nstat]); if (!$nstat) { $self-debug(1, --- closed ssh tunnel. Netstat result empty); $tunnelok=0; } Is this really computationally expensive? (I already know this makes my code not portable) Im not calling these very often, is there a better way to do this? thanks, Matt
Open a HTM Page
Is there any way to open a HTM page from the Perl program? When the script runs, it opens the page after some conditions were checked. Thanks in advance for you help.
Ugly Code..How to beautify or at least clarify
I have a Perl program that loads a bunch of report names in a hash (%TITLES). I then read through files in a directory trying to match the report name of the file to the report name in the hash. When I get a hit, I use the reference of the hash hit to pick up an array that tells me on what line of the report I will find certain items. I have it workingHooray for me :-) But I don't like what I have to do to get it working. Here is a snippet with some explanation to explain what is or isnot happening. Although, I have shown the first of 2 other processing sections ( there is one for $rptid, $edate, $rdate) I have shown only the first. The other two are the same exact structure and only the regex and variable names are different. It is possible that I will process through all sections based on the flags in @values. If I have to adjust the line count to match the flag I was just doing a FILE; and assumed (silly me) that $_ would be set. I found that it wasn't so I assigned it. Hope this is clear enough to be of some help. If not I am wearing my asbestos suit today. :-) Looking for a better way..TIA...MY COMMENTS SNIP 152 LINELOOP:while (FILE) { read a line from FILE into $_ 153 chomp; 154 if ( $linecnt == 86 ) { # if not found in 20 155 print *ERROR**\n; 156 print $file:NO_TITLE_FOUND\n; 157 print *ERROR**\n\n; 158 last FILELOOP;# linesquit! 159 } else { 160 $fname=$file; 161 ($rptname, $rcvdate, $procdate) = split(/\./, $fname); 162 $lookup = $rptname; 163 $rptname =~ tr!d_salgpqt!- \/\\()\'!; 164 165 # We now have enough information to be able to start the lookup for the information 166 # not contained in the header page of the report. 167 # We need to look up the report name in our hash table and see what lines need to be read 168 # for the remaining parameters. 169 170 # Let's check to see if the Title is in our table. If not we need to add it and specify 171 # the proper values. This is an error and must be corrected manually and viprep re-run. 172 173 if (! exists $TITLES{$lookup}) { 174 print ERR $lookup is not defined in rtitles (or BIGlist)\n; 175 print \n\n\n***\n\n\n; 176 print $lookup not found in rtitles (BIGlist) table. It must be added\n; 177 print \n\n\n***\n\n\n; 178 next FILELOOP; 179 } 180 181 foreach $keytitle (keys %TITLES) { This is my foreach loop to find the Report Titles 182 if ( grep /$keytitle/, $lookup ) { Prior to this I have check to see if the key exists. 183 @values = @{$TITLES{$keytitle}}; 184 $im = $values[0]; 185 $rptid = $values[1]; 186 $edate = $values[3]; 187 $rdate = $values[4]; 188 189 # Check to see if we need to image this file. 190 191 if ($im == 0) { 192 print LOOKUP: $lookup\n\n; 193 next FILELOOP; 194 } 195 196 # File needs to be imaged. Now check for parameters that are valid in this report. 197 # 198 # PARM 1: Check for REPORT ID This is 1 of right now 3 sections of code that are very similar 199 # and this is where the ugliness that I am asking about comes 200 201 if ($rptid == 0) { $rptid has either a 0 (the entity doesn't exist in this report) or 202 $rid=NO_RID; a line #. I may have to adjust the current line number ($linecnt) 203 } else { If I do then I have to do some reading in the file. 204 if ( $linecnt $rptid ) { 205 until (
module install
I'm trying to install a module as root from cpan and it is looking for my ncftp program and it is not found. What do i do now?? I'm using mandrake 7.2 on my linux server.
Re: FW: Optional Variables
On 29 Jun 2001 09:00:50 -0700, Randal L. Schwartz wrote: Chas == Chas Owens [EMAIL PROTECTED] writes: Chas my $query = Chas SELECT a.filename, a.size, a.date, b.owner, c.group Chas FROM filesystem a, outer owner b, outer group c Chas WHERE a.uid = b.uid Chas AND a.gid = b.gid; Chas my @query_options = ( Chas AND filename = , Chas AND size = , Chas AND date = Chas ); Chas my $i = 0; Chas #thanks go to Merlyn for making me think about @ARGV instead of using Chas #defined(ARGV[0]) Chas $query .= $query_options[$i++] . shift while (@ARGV); my @query_options = qw(filename size date); Yay, I finally get to stand up for myself: I thought about using just the column names, but if the option's operator should be OR or AND NOT instead of just AND? Of course, you could always require an operator, the field, an operator, and the data on the commandline like this: find_files AND filename = spec.txt AND size 1024 but this seems to be a utility script and that level of user interaction is undesirable since the point of such script is often to just make being a DBA easier. Of course, such a script would probably be much nicer to use if we were to use Getopt::Std, but then all of these tricks are pointless. $query .= sprintf AND %s = %s, shift @query_options, shift while @ARGV; Except I'd probably go the placeholder approach... my @query_options = qw(filename size date); my $query = join , 'END', map AND $_ = ?, @query_options[0..$#ARGV]; SELECT a.filename, a.size, a.date, b.owner, c.group FROM filesystem a, outer owner b, outer group c WHERE a.uid = b.uid AND a.gid = b.gid END my $sth = $dbh-prepare($query); $sth-execute($query, @ARGV); $sth-mumble_fetch_mumble... That way you don't have to worry about weird values in @ARGV. -- 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! -- Today is Setting Orange, the 34th day of Confusion in the YOLD 3167 Hail Eris!
Re: short filehandle question
On Fri, Jun 29, 2001 at 02:28:50PM +0200, Ela Jarecka wrote: Hi, Executing my program with -w option I get the following warning: 'Value of HANDLE construct can be 0; test with defined() at readData line 65535.' Surely I do not have 65535 lines in my program, but I suspect this one: #reading data open (FILEH, $filename) or die Can't open file!\n; while ($line = FILEH) { I have no idea where the others are going with their lexical vs. non-lexical filehandle, so you should probably disregard that avenue. Your problem is probably in that area. Specifically, it's likely while loop. Your intent is to read until EOF, but it will fail if FILEH returns just 0, which it can if the last line in the file contains only a 0 and no trailing newline. You need to test for defined'ness, not truth: while (defined($line = FILEH)) { ... } The error message you describe is in perldoc perldiag. More recent versions will actually turn your loop form into the loop form above (checking for defined'ness). What this means is that if you're using a more recent version (at the least, 5.004 and beyond) your problem lies elsewhere, in one of the other constructs listed in the perldiag entry. Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com --
Re: background processing (again?)
dunno about the select module, but a normal call to select will block. that is why in my other mail i had given you the option of blocking on select in another thread/process /kk On Fri, Jun 29, 2001 at 12:36:20PM -0400, Ronald J. Yacketta wrote: Maybe I just don't understand.. but wont there _always_ be data to read from netstat? to me, it seems as tho the loop _not_ work as intended, it would always pass the can_read and read data from netstat and never parse the other code? Regards, Ron -Original Message- From: David M. Lloyd [mailto:[EMAIL PROTECTED]] Sent: June 29, 2001 10:37 To: Ronald J. Yacketta Cc: Perl Subject: RE: background processing (again?) On Thu, 28 Jun 2001, Ronald J. Yacketta wrote: I have heard doing it this way will cause grief.. need blocking i/o or something along that lines. Also, I head that the flow of the program would _stop_ when reading the data... are there any other solutions? You can get around blocking I/O by using the IO::Select module: ### PERL open NETSTAT, netstat -I hme0 $SLEEPTIME | or die Can't start netstat: $!\n; my $select = new IO::Select; $select-add_reader(\*NETSTAT); while (1) { if ($select-can_read(0)) { # There is data so read it } else { # do something else while we wait } } ### END PERL P.S. kk, I never did get you example code working under Solaris, it works fine under Linux If you're talking about my code, be aware that 'netstat' takes different arguments based on which platform you're on. - D [EMAIL PROTECTED]
Re: Open a HTM Page
On Fri, 29 Jun 2001, Brett W. McCoy wrote: Is there any way to open a HTM page from the Perl program? When the script runs, it opens the page after some conditions were checked. open(HTML, header.html) or die Could not open header.html: $!\n; while(HTML) { print } close(HTML) ^^^ Oops, left off the final ; ! -- Brett http://www.chapelperilous.net/btfwk/ But Officer, I stopped for the last one, and it was green!
RE: System calls in perl for ps and netstat - less expensive way?
sorry about the terse code snippet Basically, I have an SSH tunnel that is controlled by another process and I want to tell when that ssh tunnel is closed. (I have both the PID for this SSH tunnel process and the port # of the local side of the tunnel) I am checking for closed tunnels 2 ways: 1) if the process is defunct (i realize that the code I wrote doesnt quite illustrate this 2nd part... sorry) 2) if netstat -an | grep localhost:(port#) shows no output, then I know that the localhost port is no longer listening, hence the tunnel is closed. I guess my question is 2 part: 1) Id like to know if theres a better way to do this 2) Is it really horribly expensive to do this with sys calls? -Original Message- From: Kipp, James [mailto:[EMAIL PROTECTED]] Sent: Friday, June 29, 2001 9:52 AM To: 'Matt Weatherford'; [EMAIL PROTECTED] Subject: RE: System calls in perl for ps and netstat - less expensive way? Hi Matt Can you describe a little bit what U are trying to do or include more of the code. Depending on what U are trying to do, there may be less expensive alternatives Thanks Jim From PERL, I have been doing some system calls like this: (see * lines) * my $procentry=`ps -ef | grep -v grep | grep $self-{pid} `; chomp $procentry; $self-debug(1, Procentry: [$procentry]); if ($procentry =~ /\defunct\/ ) { $self-debug(1, --- closed ssh tunnel. Tunnel proc defunct); $tunnelok=0; } * my $nstat=`netstat -an | grep '127.0.0.1' `; chomp $nstat; $self-debug(1, NStat: [$nstat]); if (!$nstat) { $self-debug(1, --- closed ssh tunnel. Netstat result empty); $tunnelok=0; } Is this really computationally expensive? (I already know this makes my code not portable) Im not calling these very often, is there a better way to do this? thanks, Matt
Re: module install
On Fri, Jun 29, 2001 at 11:31:28AM -0500, Hal Wigoda wrote: When you install a perl module from CPAN should you do it as root??? Often the answer you'll see in response to this question is yes, as evidenced by the two answers I see to your question already. The real answer is it depends. On several of my home systems I have a specific user named, aptly, 'perl', that I use for installing modules. It owns all of the Perl library directories and the libraries themselves. I prefer this to running untrusted code from CPAN (Makefile.PL, the generated Makefile, etc.). YMMV Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com --
Re: module install
You're probably using $ perl -MCPAN -e shell install moduleName If you're not, you should. Anyway, this method tries 3 different ways to download a module, lwp, Net::Ftp and ncftp. Any one of these should work if you have them installed. If not, install them. Hal Wigoda [EMAIL PROTECTED] wrote: I'm trying to install a module as root from cpan and it is looking for my ncftp program and it is not found. What do i do now?? I'm using mandrake 7.2 on my linux server.
Web Page Interaction...
All, I have done some searching, looking for a module for interacting with web pages. The only module, that appears to be related is LWP. I read through those docs, and, I am a novice, so they are a little confusing. Does anyone know of a good tutorial, resource for an explanation on how to interact with different types of web pages. For example, dealing with login dialog boxes, forms, etc. ? Thank you for any direction you can point me in.. Craig [EMAIL PROTECTED] Pager Numeric: 1-877-895-3558 Email pager: [EMAIL PROTECTED] -- You will never find time for anything. If you want time, you must make it. Charles Buxton
Beginning
Where should I begin? I would like to get to know perl but do not know where to start. Are there recommended books/websites etc. for in depth documentation? Any suggestions would be greatly appreciated. Scott Dortch Director of Operations The Order Fulfillment Group
Re: Inheritance of package global variables
On Fri, Jun 29, 2001 at 12:14:23AM -0400, Richard J. Barbalace wrote: I don't really want to export the variables; I'm not modifying them in the parent package, just copying and expanding them in the inheriting package. Well then, you are copying and modifying as simply as it can be done. Again, though, I would avoid using variables like that, and instead go for a class method approach: package Foo; sub attributes { return (foo = undef) } sub set { my($self, $attribute, $value) = (shift, shift, shift); my %attr = $self-attributes; if (defined $attr{$attribute}) { ... } else { ... } } package Foo::Bar use base qw(Foo); sub attributes { my $self = shift; return ($self-SUPER::attributes(), foo_bar = '.*') } This will get costly, so perhaps some caching is in order. The point is, classes shouldn't be getting to class data except through class methods. I have not been able to find a perl module that would allow this sort of inheritance and data validation; does anyone know of one that does this? Or can anyone suggest a better way of doing what I want? If you haven't already, you should check the Class:: modules on CPAN to see if something already does this. However, data validation is so arbitrary that the closest you can get is probably something that sets up your inherited accessors and then calls back to your code, if you provide it, for verifying the data. Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com --
Re: Beginning
Scott, I have read a couple of books. It depends on your background. I have a highly technical background, but knew zero about programming. I started with Perl for dummies, and then purchased Learning Perl. I found that a good transition for me, but you may be able to jump right. Craig [EMAIL PROTECTED] Pager Numeric: 1-877-895-3558 Email pager: [EMAIL PROTECTED] -- You will never find time for anything. If you want time, you must make it. Charles Buxton - Original Message - From: Scott Dortch [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, June 29, 2001 1:42 PM Subject: Beginning Where should I begin? I would like to get to know perl but do not know where to start. Are there recommended books/websites etc. for in depth documentation? Any suggestions would be greatly appreciated. Scott Dortch Director of Operations The Order Fulfillment Group
Re: module install
On Fri, Jun 29, 2001 at 12:10:04PM -0500, Hal Wigoda wrote: I'm trying to install a module as root from cpan and it is looking for my ncftp program and it is not found. What do i do now?? I'm using mandrake 7.2 on my linux server. You can install ncftp from your mandrake CDs, or through the RPM or other such package. This is not an error. You should have 'ftp' installed, and the cpan interface is looking for a variety of ways to FTP files, ncftp being preferable to ftp. Ignore the message and let CPAN find your modules through 'ftp' instead. Z.
Re: Web Page Interaction...
CGI.pm is the most advanced module around for dealing with forms. At 13:44 29.06.2001 -0400, Craig S Monroe wrote: All, I have done some searching, looking for a module for interacting with web pages. The only module, that appears to be related is LWP. I read through those docs, and, I am a novice, so they are a little confusing. Does anyone know of a good tutorial, resource for an explanation on how to interact with different types of web pages. For example, dealing with login dialog boxes, forms, etc. ? Thank you for any direction you can point me in.. Craig [EMAIL PROTECTED] Pager Numeric: 1-877-895-3558 Email pager: [EMAIL PROTECTED] -- You will never find time for anything. If you want time, you must make it. Charles Buxton Aaron Craig Programming iSoftitler.com
RE: Running PERL as root
Here's a suggestion. When you receive data from a form, the cgi that parses this data should run as an ordinary user. The process will act as a buffer, cleaning data, looking for invalid values, and other oddities. Then when all concerns are satisfied, the data is written to disk to be picked up by another process that IS running as root. ... and if you're really paranoid, you can have the second root-privilaged process check over the data again, just in case it was changed after being written to disk. No method is totally secure, but at least this way insulates you from direct attacks against your code. I welcome comments from all on this method. Bill Pierson [EMAIL PROTECTED] wrote: Thanks for your replies. Actually, I'd like to be able to modify system config files, stop and restart daemons, etc. I'm not aware of the different ways to accomplish this; any tips would be appreciated. The server is in a protected environment. --Bill -Original Message- From: Farouk Khawaja [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 27, 2001 10:44 PM To: Bill Pierson; [EMAIL PROTECTED] Subject: Re: Running PERL as root Bill Pierson [EMAIL PROTECTED] wrote: I have a quick question about running a perl program as root via CGI. I would assume it's platform dependant, and in my situation I have Linux Redhat 7.1 w/Apache 1.3.19 webserver. This question is a little off-topic, however I'm guessing that a few of you may have tackled this issue before. Thanks again, --Bill I wouldn't run any CGI script as root, no matter how securly I belive I've written it. What are you trying to do that would require root permission to accomplish? Maybe you can explore alternatives.
Re: CSS in Perl
Hi there Scuse any netiquette errors - I'm new to mailing lists so I'm a bit shaky on the rules. Use an external style sheet to hold your css information then all you need to do is add the following line to your perl code in the head tags in the html output link rel=stylesheet type=text/css href=mystyle.css / to put this into a perl context print endofhtm; Content-type:text/html html head link rel=stylesheet type=text/css href=mystyle.css / /head body output of search results here /body /html endofhtm mystyle.css is basically just a text file containing your style sheet info. You can add the style reference to any html output to apply the same style to any document. It also allows you to update your whole site with a new style sheet just by editing one document. Hope this helps Rick - Original Message - From: German, Douglas [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, June 29, 2001 2:24 PM Subject: CSS in Perl Hi I'm in the process of developing an intranet which includes a site search engine. Having downloaded Perl scripts from the internet, I am now tweaking those scripts to fit in with the rest of the site. I have the initial search box embedded in an ASP page which on submission calls the Perl script in the cgi-bin. This script writes the html and displays the results. The ASP and HTML pages on the site use CSS, and I need to include the same styles on the page that returns the search results, to give the site consistency. Does anyone know of a way this can be accomplished, apart from rewriting the entire CSS in Perl, which is beyond my capabilities? Thanks Doug German [EMAIL PROTECTED]
Re: module install
Hal Wigoda [[EMAIL PROTECTED]] quoth: *I'm trying to install a module as root *from cpan *and it is looking for my ncftp program *and it is not found. * *What do i do now?? * *I'm using mandrake 7.2 on my linux server. Configure CPAN.pm to use ftp elaine@chaos /home/chaos/elaine perl -MCPAN -eshell cpan shell -- CPAN exploration and modules installation (v1.59) ReadLine support enabled cpan o conf ftp ftp/usr/bin/ftp cpan o conf ncftp ftp/usr/local/bin/ncftp cpan o conf ncftpget ftp/usr/local/bin/ncftpget --- 'o conf' with no args will display all of the current configs for CPAN.pm Simply undefine ncftp and ncftpget and it's won't bother you anymore for ncftp. e.
Re: loop counting
On Fri, 29 Jun 2001, Bob Mangold wrote: Is there a perl variable that automatically counts loop iterations. Such that I don't have to use '$count': foreach (@array){ $count++; ..whatever.. } You can always do, if you need a loop variable: foreach my $i (0..$#array) { #do stuff with $array[$i] } -- Brett http://www.chapelperilous.net/btfwk/ At times discretion should be thrown aside, and with the foolish we should play the fool. -- Menander
Re: loop counting
On Fri, Jun 29, 2001 at 02:58:20PM -0400, Jeff 'japhy' Pinyan wrote: No there is not. Either do: my $i = 0; for (@foo) { # ... } continue { $i++ } or do: for my $i (0 .. $#foo) { my $element = $foo[$i]; # ... } or for (my $i = 0; $i @foo; $i++) { ... } for (;;) isn't a bad word. :) Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com --
Re: Beginning
Scott, I knew nothing when I started. I found a copy of a program and dug out every word until it I understood it and the flow from top to bottom. I have found this a good way to learn any language. Jerry Scott Dortch wrote: Where should I begin? I would like to get to know perl but do not know where to start. Are there recommended books/websites etc. for in depth documentation? Any suggestions would be greatly appreciated. Scott Dortch Director of Operations The Order Fulfillment Group
Re: loop counting
--- Bob Mangold [EMAIL PROTECTED] wrote: Is there a perl variable that automatically counts loop iterations. Such that I don't have to use '$count': foreach (@array){ $count++; ..whatever.. } Lot's of people with suggestions, but I have a question -- what are you using $count for? Why do you need it? __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
RE: Idea.. OCR in perl?
Pierre, I'm working on such solution right now. Hit a dead-end with PerlMagick on Win32, so this weekend I'll start over on Linux. Here's what I found: Manipulate images (i.e.,crop) http://www.eecs.umich.edu/~addi/perl/Imager/ ImageMagick - cut and manipulate images http://sourceforge.net/projects/netpbm/ Convert Image to OCR-able format (pnm files) http://hegel.ittc.ukans.edu/topics/linux/man-pages/man1/tifftopnm.1.html ImageMagick: convert/mogrify - (?) http://www.eecs.umich.edu/~addi/perl/Imager/ http://sourceforge.net/projects/netpbm/ http://www.megaloman.com/~hany/RPM/doors3.0/jr/netpbm-progs-9.5-6.i386.html OCR utilities (pnm files) http://freshmeat.net/projects/gocr/ http://lem.eui.upm.es/ocre.html - OCR pnm files http://web.mit.edu/afs/sipb.mit.edu/user/jhawk/src/quinefaut-0.5.tgz Empirical success story: http://leb.net/blinux/list-archive/blinux-list/2000/msg01702.html I tried to get ImageMagick-PerlMagick to work with Win32 to no avail (compiling from source produced fatal errors). I'll instead use Linux, as that is apparently better supported. (My laptop in WinME and would be most convenient to test with...I have no love of Win32!) First, I need to try perl Imager Linux. If that doesn't cut it (no pun intended) then I'll install ImageMagick and PerlMagick on Linux. Failing that, I'll move to GIMP with Perl-fu interface. Second, convert the tiff to pnm and OCR it. -- Robert Taylor mailto:[EMAIL PROTECTED] Thermeon Corporation http://www.thermeon.com/ Santa Ana, CA Phone: (714) 731-9191 Fax: (714) 731-5938 WebRes Demo site http://webres.thermeon.com/webres/res.html WebRent Demo sitehttps: /secure.thermeon.com/webrent/index.html (please request username and password for access) -Original Message- From: Pierre Smolarek [SMTP:[EMAIL PROTECTED]] Sent: Friday, June 29, 2001 2:07 AM To: [EMAIL PROTECTED] Subject: Idea.. OCR in perl? Does anyone know if there is either a c app that will take an image and ocr it ? (Character recognition) That would be cool as you could develop some nice apps with that in perl. Pierre
Re: loop counting
Paul, Within the loop, some other programs are executed and occasionally it may take a few minutes to complete everything and then continue. So I'm just throwing a little counter to STDOUT so I can monitor the progress, to ensure it doesn't get hung up somewhere. I knew of all the different ways to do it, but since my programs tend to deal a lot with arrays and looping through them I run into this issue (of how to count through them) all the time. I was just curious if there was another way. It seems to me that since Perl has the ability to know things like where a search left off, or what the last matched item was, or what line of a file it's reading, that it might be keeping track of this too. -Bob --- Paul [EMAIL PROTECTED] wrote: --- Bob Mangold [EMAIL PROTECTED] wrote: Is there a perl variable that automatically counts loop iterations. Such that I don't have to use '$count': foreach (@array){ $count++; ..whatever.. } Lot's of people with suggestions, but I have a question -- what are you using $count for? Why do you need it? __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/ __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
Formatting
What would cause this format for the output file to result in the error message Format not terminated at end of line : format OUTPUTFORMAT = @,@ ,@ ,@ $servicename,$filename ,$service_type_name ,$node_name . These values are assigned by an array that gets populated based on a select statement. I call it in the body of my code like this: write (OUTPUTFORMAT); Thanks, Kim
Re[OT]loop counting
--- Bob Mangold [EMAIL PROTECTED] wrote: Within the loop, some other programs are executed and occasionally it may take a few minutes to complete everything and then continue. So I'm just throwing a little counter to STDOUT so I can monitor the progress, to ensure it doesn't get hung up somewhere. lol -- ok. I was wondering. I saw lot's of suggestions, but wondered if any of them really helped you. From the look of it, I'd say the method you're using is about as good as any. I knew of all the different ways to do it, but since my programs tend to deal a lot with arrays and looping through them I run into this issue (of how to count through them) all the time. I was just curious if there was another way. Lots, but probably none much better. For this, I probably would use } continue { $count++ } but only to isolate this metadata from actual programatic logic. It seems to me that since Perl has the ability to know things like where a search left off, or what the last matched item was, or what line of a file it's reading, that it might be keeping track of this too. Makes sense. --- Bob Mangold [EMAIL PROTECTED] wrote: Is there a perl variable that automatically counts loop iterations. Such that I don't have to use '$count': foreach (@array){ $count++; ..whatever.. } Lot's of people with suggestions, but I have a question -- what are you using $count for? Why do you need it? __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
Re: Web Page Interaction...
I took a look at the cgi.pm. It looks as though it deals with receiving variables from forms, writing dynamic pages, etc. Is this your impression? What I am looking to do, is fill out pages as if a human(or something close) were doing it. For example, visit http://www.yoursite.com click on a particular link, etc Am I not looking close enough? Craig [EMAIL PROTECTED] Pager Numeric: 1-877-895-3558 Email pager: [EMAIL PROTECTED] -- You will never find time for anything. If you want time, you must make it. Charles Buxton - Original Message - From: Lara J. Fabans [EMAIL PROTECTED] To: Craig S Monroe [EMAIL PROTECTED] Sent: Friday, June 29, 2001 1:59 PM Subject: Re: Web Page Interaction... I'd recommend looking at CGI.pm instead of LWP. It should come with your distribution of perl. www.webmonkey.com has some great tutorials. And there's a lot of books out there on how to use the module. It makes everything just so much easier. lara At 01:44 PM 6/29/2001 -0400, you wrote: All, I have done some searching, looking for a module for interacting with web pages. The only module, that appears to be related is LWP. I read through those docs, and, I am a novice, so they are a little confusing. Does anyone know of a good tutorial, resource for an explanation on how to interact with different types of web pages. For example, dealing with login dialog boxes, forms, etc. ? Thank you for any direction you can point me in.. Craig [EMAIL PROTECTED] Pager Numeric: 1-877-895-3558 Email pager: [EMAIL PROTECTED] -- You will never find time for anything. If you want time, you must make it. Charles Buxton - Lara J. Fabans Lodestone Software, Inc [EMAIL PROTECTED]
Re: Web Page Interaction...
I took a look at the cgi.pm. It looks as though it deals with receiving variables from forms, writing dynamic pages, etc. Is this your impression? What I am looking to do, is fill out pages as if a human(or something close) were doing it. For example, visit http://www.yoursite.com click on a particular link, etc Am I not looking close enough? Craig [EMAIL PROTECTED] Pager Numeric: 1-877-895-3558 Email pager: [EMAIL PROTECTED] -- You will never find time for anything. If you want time, you must make it. Charles Buxton - Original Message - From: Lara J. Fabans [EMAIL PROTECTED] To: Craig S Monroe [EMAIL PROTECTED] Sent: Friday, June 29, 2001 1:59 PM Subject: Re: Web Page Interaction... I'd recommend looking at CGI.pm instead of LWP. It should come with your distribution of perl. www.webmonkey.com has some great tutorials. And there's a lot of books out there on how to use the module. It makes everything just so much easier. lara At 01:44 PM 6/29/2001 -0400, you wrote: All, I have done some searching, looking for a module for interacting with web pages. The only module, that appears to be related is LWP. I read through those docs, and, I am a novice, so they are a little confusing. Does anyone know of a good tutorial, resource for an explanation on how to interact with different types of web pages. For example, dealing with login dialog boxes, forms, etc. ? Thank you for any direction you can point me in.. Craig [EMAIL PROTECTED] Pager Numeric: 1-877-895-3558 Email pager: [EMAIL PROTECTED] -- You will never find time for anything. If you want time, you must make it. Charles Buxton - Lara J. Fabans Lodestone Software, Inc [EMAIL PROTECTED]
Re: Optional Variables
my $option = $ARGV[0] || 1; And what if $ARGV[0] equal to 0 ? Ops .. Remember what evaluates to FALSE : * 0 * 0 * empty string * undef
Re: Web Page Interaction...
CGI.pm can also create forms. And to have the pages pre-filled in, just use $q-textfield('my value for this particular element') set and it will be prefilled in. (all of the rest of the form elements would use something like: $q-checkbox_group(-values=['Shampoo', 'Toothbrush', 'Potato Salad'], -name='mypopup'); But I'm not sure how you'd say 'checked' for one particular one. Lara - Original Message - From: Craig S Monroe [EMAIL PROTECTED] To: Beginners@Perl (E-mail) [EMAIL PROTECTED] Sent: Friday, June 29, 2001 1:02 PM Subject: Re: Web Page Interaction... I took a look at the cgi.pm. It looks as though it deals with receiving variables from forms, writing dynamic pages, etc. Is this your impression? What I am looking to do, is fill out pages as if a human(or something close) were doing it. For example, visit http://www.yoursite.com click on a particular link, etc Am I not looking close enough? Craig [EMAIL PROTECTED] Pager Numeric: 1-877-895-3558 Email pager: [EMAIL PROTECTED] -- You will never find time for anything. If you want time, you must make it. Charles Buxton - Original Message - From: Lara J. Fabans [EMAIL PROTECTED] To: Craig S Monroe [EMAIL PROTECTED] Sent: Friday, June 29, 2001 1:59 PM Subject: Re: Web Page Interaction... I'd recommend looking at CGI.pm instead of LWP. It should come with your distribution of perl. www.webmonkey.com has some great tutorials. And there's a lot of books out there on how to use the module. It makes everything just so much easier. lara At 01:44 PM 6/29/2001 -0400, you wrote: All, I have done some searching, looking for a module for interacting with web pages. The only module, that appears to be related is LWP. I read through those docs, and, I am a novice, so they are a little confusing. Does anyone know of a good tutorial, resource for an explanation on how to interact with different types of web pages. For example, dealing with login dialog boxes, forms, etc. ? Thank you for any direction you can point me in.. Craig [EMAIL PROTECTED] Pager Numeric: 1-877-895-3558 Email pager: [EMAIL PROTECTED] -- You will never find time for anything. If you want time, you must make it. Charles Buxton - Lara J. Fabans Lodestone Software, Inc [EMAIL PROTECTED]
Re: Web Page Interaction...
Hi, I have been something similar lately to what u want to do. Browsing thru webpages.filing out formsfollowing links on a page etc. LWP::UserAgent and HTTP::Request can be used to do that. I would suggest you take a look at Web Client Programming with Perl by Clinton Wong - QReilly publishers also, there's a chapter on Web Automation in the Perl Cookbook. Hope this helps. Prachi _ Get your FREE download of MSN Explorer at http://explorer.msn.com
Re: Open a HTM Page
you could just do print `cat file.html` if (condition); On Fri, 29 Jun 2001, Mike Truong wrote: Is there any way to open a HTM page from the Perl program? When the script runs, it opens the page after some conditions were checked. Thanks in advance for you help.
Timeofday jumping
Hi, has anyone used the timeofday function in Time::Hires on Win32? The reason I ask is that I am repeatedly getting and printing the microseconds: @thetime = timeofday; print $thetime[1]; The microseconds only have a millisecond componant, so they are of the range 00 to 999000 (the last three digits are always zero). I understand this might be a limit of the granularity of the Win32 implementation, but if someone could confirm this, it would be cool. Milliseconds is fine for my uses. My problem comes from the fact that the microsecond count does not increase consistantly. If I loop around the above code, it produces the same value for say 10 iterations, and then will jump to a higher number and repeat that for 10 iterations, rather than increasing each loop, or increasing the same amount each loop. So the output at the crossover point would be like: 718000 718000 718000 718000 734000 734000 734000 See, a sudden increase of 16000 us in the middle of the same loop. Can anyone explain this? Thanks, Paul Global WebMail - Delivered by Global Internet www.global.net.uk
Simple Split Question
I'm having trouble with what I think is a very simple split question. I've got a line of text something like: DimView 1 All DimView 2 Some DimView 3 Most DimView 4 None I want a hash with (1, All, 2, Some, 3, Most, 4, None) I'm spitting on /DimView/, but I can't get the syntax to throw it into the hash correct. Can one of you thow me a couple of lines of code to get me through this? Thanks, Scott
Problem with hash value
Hi Members, It seemed that a value was incorrectly retrieved from the hash list in the following small Perl script. . #!/usr/local/bin/perl sub card{ my %card_map; my ($num)=@_; @card_map{1..9}= qw(one two three four five six seven eight nine); if ($card_map{$num}) { $card_map{$num}; } else { $num; } } while () { chomp; print card of $_ is: card($_), \n; } The problem is when a numeric value is inputed, it can't get correct correspondent English name. Any help is appreciated
RE: [OT:style]deleting a line with a particular string.
At 10:21 AM 6/29/01 +1000, Sam Lander wrote: At a shell prompt / command line, enter: perl -ne '/string/ or print' file where string is the string and file is the file. I prefer 'print unless /string/'. As if it matters. ;o] I wanted to do this just today. Although, I want to tidy up the resulting line a bit by deleting everything before a colon, so I tried this: perl -ne /string/ print s/.*:// file I was surprised that I got this: 111 (one '1' for each match) A bit of playing gave me: perl -ne /Recipient/ s/.*:// print Which gave me what I wanted, but is rather unsatisfying (esp to the sedder in me). What do other people do? Shouldn't DWIM come into play here? The trouble is that WYM is likely to be different for these cases: if (s/foo/bar/) { ... } print s/foo/bar/; Perl 6 will be able to tell (easier) whether it's in a numeric or boolean context rather than a string context and maybe the designers will consider this possibility. I know that I have repeatedly had to change a map s/foo/bar, ... into a map { s/foo/bar/; $_ } ... so it's not just what YM. -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com
Re: Problem with hash value
- Original Message - From: Wang, Lanbo [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, June 30, 2001 12:04 AM Subject: Problem with hash value Hi Members, It seemed that a value was incorrectly retrieved from the hash list in the following small Perl script. . #!/usr/local/bin/perl sub card{ my %card_map; my ($num)=@_; @card_map{1..9}= qw(one two three four five six seven eight nine); You are putting the numbers 0..9 in the array @card_map here, not in the hash %cardmap. Those are different things. You should acces the array instead. Another top is to declare and fill @card_map outside the function. It only needs to be filled once. Tru this: #!/usr/local/bin/perl my @card_map{1..9}= qw(one two three four five six seven eight nine); sub card{ return $card_map[$_[0]] || $_[0]; } while () { chomp print card of $_ is: card($_), \n; } Maarten
Re: Simple Split Question
Well, the reason it's not working is that there is only one Dimview between pairs, for a hash you need seperators between all elements. Here's a way to do it, although I bet others can come up with a quicker/more efficient way: code my (%hash); $_ = 'DimView 1 All DimView 2 Some DimView 3 Most DimView 4 None'; s/DimView file://g; s/\//g; %hash = split( / / ); /code # Note, for those of you who have an option in your email program to highlight web addresses the DimView line may have an extra file: in it. Mine does *mumble* Took me a few minutes to figure out why! - Original Message - From: Seitz, Scott [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, June 28, 2001 2:32 PM Subject: Simple Split Question I'm having trouble with what I think is a very simple split question. I've got a line of text something like: DimView 1 All DimView 2 Some DimView 3 Most DimView 4 None I want a hash with (1, All, 2, Some, 3, Most, 4, None) I'm spitting on /DimView/, but I can't get the syntax to throw it into the hash correct. Can one of you thow me a couple of lines of code to get me through this? Thanks, Scott
Re: Problem with hash value
sub card{ my %card_map; my ($num)=@_; @card_map{1..9}= qw(one two three four five six seven eight nine); You are putting the numbers 0..9 in the array @card_map here, not in the hash %cardmap. No he isn't. (He's using a hash slice, which is fine.) I would think you are always getting 'one', right? That's because: my ($num) = @_; puts the length of @_ in $num. You want: my ($num) = shift; or my ($num) = @_[0]; hth.
Re: Simple Split Question
--- Seitz, Scott [EMAIL PROTECTED] wrote: I'm having trouble with what I think is a very simple split question. I've got a line of text something like: DimView 1 All DimView 2 Some DimView 3 Most DimView 4 None I want a hash with (1, All, 2, Some, 3, Most, 4, None) I'm spitting on /DimView/, but I can't get the syntax to throw it into the hash correct. Can one of you thow me a couple of lines of code to get me through this? Try this: my $str = 'DimView 1 All DimView 2 Some DimView 3 Most DimView 4 None'; my @pairs = split /\s*Dimview\s*/, $str; my %hash; for (@pairs) { my ($key,$val) = split /\s/; $hash{$key} = $val; } __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
Re: Optional Variables
On Fri, 29 Jun 2001, M.W. Koskamp wrote: my $option = @ARGV ? shift : DEFAULT VALUE; Above option only works for 1 parameter tho (and commandline arguments). For function calls i like to use 'named parameters' by accepting a hash of options. Well, yeah, but the topic *was* command-line arguments, not function arguments. You can easily loop through @ARGV, unshifting as you go, until @ARGV is depleted and default values assigned. -- Brett http://www.chapelperilous.net/btfwk/ A free society is one where it is safe to be unpopular. -- Adlai Stevenson
Re: Problem with hash value
I would think you are always getting 'one', right? That's because: my ($num) = @_; puts the length of @_ in $num. Sorry, I'm being an idiot. You were doing the right thing. $ more number 3 5 $test10.pl number ``rd bard Hmm. print card of $_ is: card($_), \n; Ah, this looks suspect. No operator between the first string and the sub call. This is your problem. Play with this and let us know what's going on: perl -e 'sub f { foo }; print bar f' Gotta run...
Re: Problem with hash value
while () { chomp; print card of $_ is: card($_), \n; } ^ Add a comma (,) or a string cat (.) between the quote and the function :-) Aziz,,, On Fri, 29 Jun 2001 18:04:33 -0400, Wang, Lanbo said: Hi Members, It seemed that a value was incorrectly retrieved from the hash list in the following small Perl script. . #!/usr/local/bin/perl sub card{ my %card_map; my ($num)=@_; @card_map{1..9}= qw(one two three four five six seven eight nine); if ($card_map{$num}) { $card_map{$num}; } else { $num; } } while () { chomp; print card of $_ is: card($_), \n; } The problem is when a numeric value is inputed, it can't get correct correspondent English name. Any help is appreciated _ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com
Re: Problem with hash value
--- Me [EMAIL PROTECTED] wrote: my ($num) = @_; puts the length of @_ in $num. I don't think so? The parens should give $num a list context. It should have the first value in @_. Right? __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
RE: Beginning
Learning languages by reverse engineering does not work for most people. Try Learning Perl and the Perl Cookbook for starters. Also go to http://learn.perl.org/ Cheers, Joel -Original Message- From: Jerry Preston [mailto:[EMAIL PROTECTED]] Sent: Friday, June 29, 2001 12:16 PM To: Scott Dortch Cc: [EMAIL PROTECTED] Subject: Re: Beginning Scott, I knew nothing when I started. I found a copy of a program and dug out every word until it I understood it and the flow from top to bottom. I have found this a good way to learn any language. Jerry Scott Dortch wrote: Where should I begin? I would like to get to know perl but do not know where to start. Are there recommended books/websites etc. for in depth documentation? Any suggestions would be greatly appreciated. Scott Dortch Director of Operations The Order Fulfillment Group
Re: Problem with hash value
On Fri, Jun 29, 2001 at 06:04:33PM -0400, Wang, Lanbo wrote: #!/usr/local/bin/perl This is your first mistake. You forgot -w and use strict; always use both when debugging code. It wouldn't have helped you here, but I guarantee you it will in the future. So: #!/usr/local/bin/perl -w use strict; sub card{ my %card_map; my ($num)=@_; @card_map{1..9}= qw(one two three four five six seven eight nine); if ($card_map{$num}) { $card_map{$num}; } else { $num; } } while () { chomp; print card of $_ is: card($_), \n; Here's your problem, you forgot a comma after the first argument to print. This is being evaluated as (in the case of 7 being input): print card of 7 is: seven, \n; is a bitwise operator, in this instance operating on strings. card of 7 is seven results in card. What you should be doing is, of course: print card of $_ is, card($_), \n: The is unnecessary. } Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com --
Re: Problem with hash value
On Sat, Jun 30, 2001 at 12:28:11AM +0200, M.W. Koskamp wrote: From: Wang, Lanbo [EMAIL PROTECTED] Hi Members, #!/usr/local/bin/perl sub card{ my %card_map; my ($num)=@_; @card_map{1..9}= qw(one two three four five six seven eight nine); You are putting the numbers 0..9 in the array @card_map here, not in the hash %cardmap. Those are different things. You should acces the array instead. @card_map{1..9} = (...) is a hash slice assignment; it does indeed initialize %card_map, not @card_map. It's a good point that he should be using an array, though. Another top is to declare and fill @card_map outside the function. It only needs to be filled once. Another good point. Tru this: #!/usr/local/bin/perl my @card_map{1..9}= qw(one two three four five six seven eight nine); Wrong syntax here, though, for various reasons. You wanted my @card_map; @card_map[1..9] = qw(...); You can't declare a hash or array slice, so the declaration has to be seperate. Also, of course, @card_map{1..9} is still a hash slice. sub card{ return $card_map[$_[0]] || $_[0]; } while () { chomp print card of $_ is: card($_), \n; } You missed the mistake too; the missing comma after print's first argument is the problem, everything else he has is, technically, fine. Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com --
RE: Beginning
One more note for beginners (like myself) buying Perl books - The Perl CD Bookshelf is $71.96 (USD) at Amazon and $47.97 (USD) at FatBrain.com. Shop around. (I have any no financial ties to FatBrain just looking to help the end user) -Original Message- From: Stout, Joel R [mailto:[EMAIL PROTECTED]] Sent: Friday, June 29, 2001 4:35 PM To: [EMAIL PROTECTED] Subject: RE: Beginning Learning languages by reverse engineering does not work for most people. Try Learning Perl and the Perl Cookbook for starters. Also go to http://learn.perl.org/ Cheers, Joel -Original Message- From: Jerry Preston [mailto:[EMAIL PROTECTED]] Sent: Friday, June 29, 2001 12:16 PM To: Scott Dortch Cc: [EMAIL PROTECTED] Subject: Re: Beginning Scott, I knew nothing when I started. I found a copy of a program and dug out every word until it I understood it and the flow from top to bottom. I have found this a good way to learn any language. Jerry Scott Dortch wrote: Where should I begin? I would like to get to know perl but do not know where to start. Are there recommended books/websites etc. for in depth documentation? Any suggestions would be greatly appreciated. Scott Dortch Director of Operations The Order Fulfillment Group
RE: Simple Split Question
I don't think you want to use split.. at least I wouldn't. I would do: CODE my %foo = (); my $line = 'DimView 1 All DimView 2 Some DimView 3 Most DimView 4 None'; $foo{$1} = $2 while $line =~ m/DimView (\d) ([^]+)/g; /CODE That gives me %foo as (according to Data::Dumper): { 1 = 'All', 2 = 'Some', 3 = 'Most', 4 = 'None' }; -Original Message- From: Seitz, Scott [mailto:[EMAIL PROTECTED]] Sent: Thursday, June 28, 2001 1:32 PM To: '[EMAIL PROTECTED]' Subject: Simple Split Question I'm having trouble with what I think is a very simple split question. I've got a line of text something like: DimView 1 All DimView 2 Some DimView 3 Most DimView 4 None I want a hash with (1, All, 2, Some, 3, Most, 4, None) I'm spitting on /DimView/, but I can't get the syntax to throw it into the hash correct. Can one of you thow me a couple of lines of code to get me through this? Thanks, Scott - Stephen Nelson stephen on PerlMonks (www.perlmonks.com) [EMAIL PROTECTED]