remove a char
In an array say @randomWord The second position could contain one of a thousand words, but the words all end with a comma. How can I strip that comma? I've tried using: $_=$randomWord[1]; /(.*.),/; $randomWord[1] = $_; But this is not working, any sugestions? -Mike -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Find Files Based on Age
>From within perl using built-in functions: $modification_time = (stat($file))[9]; # seconds since epoch $time = time; # now $age = $time - $modification_time; # age in seconds Gary > -Original Message- > From: Scott Burks [mailto:[EMAIL PROTECTED]] > Sent: Thursday, March 28, 2002 11:56 AM > To: [EMAIL PROTECTED] > Subject: Find Files Based on Age > > > This might be simple, but I haven't found a solution yet. I have a > script that I use on our Unix boxes that uses 'find' to get a list of > files in a certain directory that are a certain number of days old and > removes them from the system (find / -name * -mtime +45 -exec rm -rf {} > \;). I need to port this to a Windows 2000 Server (he shudders as he > says this) and haven't been able to find a command or module that will > do the same search based on the age of the file. Can anyone clue me > into some Windows magic please. > > Scott Burks > Systems Administrator > Trust Company of America > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Find Files Based on Age
>From within perl: > -Original Message- > From: Scott Burks [mailto:[EMAIL PROTECTED]] > Sent: Thursday, March 28, 2002 11:56 AM > To: [EMAIL PROTECTED] > Subject: Find Files Based on Age > > > This might be simple, but I haven't found a solution yet. I have a > script that I use on our Unix boxes that uses 'find' to get a list of > files in a certain directory that are a certain number of days old and > removes them from the system (find / -name * -mtime +45 -exec rm -rf {} > \;). I need to port this to a Windows 2000 Server (he shudders as he > says this) and haven't been able to find a command or module that will > do the same search based on the age of the file. Can anyone clue me > into some Windows magic please. > > Scott Burks > Systems Administrator > Trust Company of America > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Transfer a file via FTP
When a file is transferred via FTP, when is the EOF character added to the file (only at the end of transmission or also during the transferring)? Your help will be appreciated so much. -- Ahmed Moustafa -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: code review? bibliographic software script
> The script and associated files (a manual > page in groff, postscript, and PDF; a > manifest and a GPL license file; [snip] Any reason for the GPL license, e.g. derived work of a GPL'd program? The freer Artistic license is more common to the Perl community, I guess because some clever cookie worked out that Perl could be embedded and GPL was too restrictive for them. Not a critism, but I suspect my example reason has something to do with this. I don't have time to examine the entire file, probably few of us do. Examining just a is usually a good indicator of code quality. For those not interested in code review, switch off here. Okay, lets make my general feeling clear and bold: I think the code looks overly verbose, probably following the original too closely. In particular: 1. Some commenting is overly heavy, for example: # strict type checking use strict; 2. Perl constructs are generally better than C provides... e.g: # an array for each field: index 0 is fieldlabel, index 1 is prompt # (if any), index 2 is field type (0 is no input; 1 is input, noloop; # 2 is empty line terminated loop; 3 is backslash continued, any other # character or empty line terminated); index >2 for field contents my @numarr = ("%Z","",0); # this for all types (reference number) my @typarr = ("%X","",0); # this for all types (reference type) my @autarr = ("%A","Authors: ",2); # this for all types Can be turned into Perl like: my %field = ( num => [ "%Z", "", 0 ], typ => [ "%X", "", 0 ], aut => [ "%A", "Authors: ", 2 ] ); maybe there is a way around this too. 3. Don't do more work than you have to: my @artrec = ( [ @numarr ], [ @typarr ], [ @autarr ], [ @titarr ], [ @jurarr ], [ @datarr ], [ @volarr ], [ @pagarr ], [ @keyarr ], [ @otharr ] ); Is pretty much the same as: my @artrec = (\@numarr, \@typarr, \@titarr, ..., ...); provided you never alter @artrec or the arrays it depends on. If you end up searching through @artrec to see if something exists or not, then you are doing the wrong thing: my %artrec = ( numarr => \@numarr, typarr => \@typarr, ... ); gives you the same information, but if you can identify what name you need, then doing: my @array = @{ $artrec{numarr} }; is much simplier. 4. Use standard modules, unless someone gave you a naked perl binary and nothing else. # two variants of the program name: basename, Basename my $basnam = "$0"; $basnam =~ s#^.*/([^/]+)$#$1#; my $ucbnam = ucfirst("$basnam"); can be better rewritten as: use File::Basename; my $basename = basename; my $ucbname = ucfirst($basename); 5. Use Getopt::Std. Processing options yourself is generally a bad idea, unless the option syntax is really wierd. 6. rofftotext(): sub rofftotext { my $outrec = shift(@_); # # first, all accents and special characters $outrec =~ s/a\\\*\'/a\'/g; $outrec =~ s/a\\\*\`/a\`/g; $outrec =~ s/a\\\*\^/a\^/g; $outrec =~ s/a\\\*\:/a\:/g; $outrec =~ s/a\\\*\~/a\~/g; $outrec =~ s/A\\\*\'/A\'/g; $outrec =~ s/A\\\*\`/A\`/g; $outrec =~ s/A\\\*\^/A\^/g; $outrec =~ s/A\\\*\:/A\:/g; $outrec =~ s/A\\\*\~/A\~/g; # no tilda-e or E available in FM standard char set $outrec =~ s/e\\\*\'/e\'/g; $outrec =~ s/e\\\*\`/e\`/g; $outrec =~ s/e\\\*\^/e\^/g; $outrec =~ s/e\\\*\:/e\:/g; $outrec =~ s/E\\\*\'/E\'/g; $outrec =~ s/E\\\*\`/E\`/g; $outrec =~ s/E\\\*\^/E\^/g; $outrec =~ s/E\\\*\:/E\:/g; # no tilda-i or I available in FM standard char set Yuck! This will easily take forever. I don't know much about troff, but having so many global substitues is going to be painful. Good place to look for an alternative. Style wise: sub rofftotext { my $outrec = shift; # Don't use @_ explicitly for ($outrec) { s/a\\\*\'/a\'/g; s/a\\\*\`/a\`/g; s/a\\\*\^/a\^/g; s/a\\\*\:/a\:/g; s/a\\\*\~/a\~/g; ... } 7. Don't use blocks of independent ifs if ($fldid =~ /%F/) { for ($record) { /%A\s+([^\n\;]+)[\n\;]+/; $record = $1; } } if ($fldid =~ /%Z/) { for ($record) { /%Z\s+(\d+)/; $record = $1; } } if ($fldid =~ /%X/) { for ($record) { /%X\s+([ABIR])/; $record = $1; } } Can be rewritten as: my $action = ( '%F' => \&pc_F, '%Z' => \&pc_F, '%X' => \&pc_X ); sub pc_F { if ($fldid =~ /%F/) { for ($record) { /%A\s+([^\n\;]+)[\n\;]+/; $record = $1; } } } where those subs can be lexically scoped. 8... THE END (for my review anyway) Conclusion: Complexity = 7, due to high use of long regexs and file IO Length = 20, far too long - simplification possible Speed = 5, guessed
Re: code review? bibliographic software script
At 02:52 PM 3/28/02 -0800, ERIC Lawson - x52010 wrote: >I've made a perl script available for downloading, and would appreciate >any code review from anyone so inclined. Okay, here are a few comments. >my $interspace = 1; # 0 or 1 line: space between references >my $linespace = 1; # 1 or 2: interlinear space >my $fontsize = 9; # 8, 9, 10, 11, or 12 points [more of same] You have a number of lines like that. Consider keeping such configuration information in a hash; makes it easier to get the information from external sources if that's what you decide later. Also makes it easier when poking around the namespace to see all this collected into a %config or whatever. And hey, you then go on to get configuration information from an external file! (I swear I hadn't read that bit yet) > while () { > if ( /^[ \t]*interspace[ \t]*=[ \t]*([01])[ \t]*$/ ) { > $interspace = $1; > } [more of same] All the following lines like that can be condensed *and* made extensible with the hash approach. ># an array for each field: index 0 is fieldlabel, index 1 is prompt ># (if any), index 2 is field type (0 is no input; 1 is input, noloop; ># 2 is empty line terminated loop; 3 is backslash continued, any other ># character or empty line terminated); index >2 for field contents >my @numarr = ("%Z","",0); # this for all types (reference number) >my @typarr = ("%X","",0); # this for all types (reference type) >my @autarr = ("%A","Authors: ",2); # this for all types [more of same] This screams out for hash-of-arrays. ># variable for yes option in regexp >my $yes = "[yY][eE]?[sS]?"; [snip] > print "\n$datfil does not yet exist. Should I create it? (y/n): "; > if ( =~ /^\s*${yes}\s*/) { If you're going to be that picky about recognizing 'yes' (you also permit 'ys' :-) then perhaps you ought at least to check for 'n' in case they answer 'oui' or something like that :-) And consider taking a default answer. >if (-e $poifil) { > unless (-r $poifil && -f _ && -T _) { > print "$poifil is not readable. Exiting $basnam...\n"; exit; That's a lot of trouble to go to and it may still not be readable. Use open() to test for readability. I'm not sure why you're attempting to test for text-ness. >unless (-w $curdir) { > $reaonld = 1; # reset reaonld > print "$curdir is not writable.\n"; Again, if someone runs this on an ACL-based system such as AFS, that check is not good enough. Try and write a file. You've got a huge run of code around here... break it up into subroutine calls. This looks like it would benefit from an object-oriented analysis also. > my @nsrdate = (localtime(time)); > my $nsrdate = $nsrdate[3]; > if ($nsrdate[4] == 0) { $nsrdate .= "jan"; } > if ($nsrdate[4] == 1) { $nsrdate .= "feb"; } [snip 10 lines of predictable code] Ahem. You might want to look up strftime in POSIX.pm. Even if you don't use that, you can condense 12 lines to $nsrdate .= (qw(jan feb mar apr ...))[$nsrdate[4]]; Okay, I've run out of steam... I see some files opened read/write without locking... more scads of variables defined. Summary: Don't Repeat Yourself. You've got lots of places where you've typed virtually the same thing several times. That's a Clue that there's a better way. -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: context of function calls
At 03:39 PM 3/28/02 -0500, Nikola Janceski wrote: >remember when calling a subroutine with & prepended, prototypes are never >looked at. And also on method calls. -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: code review? bibliographic software script
On Thu, 28 Mar 2002, bob ackerman wrote: > excuse my curiosity, but what was the purpose in re-implementing the > program? you end up with something that runs slower and you need to > distribute a runtime engine. unless you plan to extend > functionality... This is a good question, but one I cannot, perhaps, fully address. First off, I should've mentioned originally that the script was written with no concern for any platform except linux. The short story is: the main user of the C program is on the verge of retirement, and had no desire to learn new tools; the C program broke when the last of our operational SunOS 4.1.4 systems was segregated from the rest of the network. The problem with the C program was, apparently, not easily fixed by the C programmers here (it involved the pointer file byte counts, which differed dramatically between the Sun/Solaris workstations and the PC's we now use to run RedHat Linux), and the principal user went into heavy sweats when the C program proved to be unusable by reason of cross-platform corruption of the index/pointer file, and consequent corruption of the database. In addition, being an inveterate meddler, I do intend to extend the functionality of the legacy program even more than I already have. My extensions so far (for example, I extended the search mechanism to enable selections based on the first author field) have been such as to not disturb the principal user; my extensions to come will be similarly nonintrusive, and involve, thus far, functions for generating more modern (for example, XHTML) output. I should also mention that, using glade-perl (D. Musgrove) and gtk-perl, I've made a gui interface that implements one (of the dozen or so) commands, the "add" command. When and if I get sufficient liberty to complete the interface, I will. Glade-perl is wonderful for this purpose, even if it is not yet as sophisticated as it will (I hope) become. best, Eric Lawson -- James Eric Lawson Research Publications Editor National Simulation Resource [EMAIL PROTECTED] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - They who strip not ideas from the marks men use for them, but confound them with words, must have endless dispute. -- Locke. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: confused about perl and jpg
"Agustin Rivera" <[EMAIL PROTECTED]> wrote in message 002201c1d6a9$4e8cec40$9865fea9@agustinr">news:002201c1d6a9$4e8cec40$9865fea9@agustinr... > You're right. I was thinking when I deemed a > valid tag. lol.. I guessed that was the case and felt a bit guilty after pressing the send button... I don't like jumping on peoples obvious mistakes too quickly...lol I was just bored and feeling helpful! =O) Wytch -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Find Files Based on Age
Scott Burks wrote: > > This might be simple, but I haven't found a solution yet. I have a > script that I use on our Unix boxes that uses 'find' to get a list of > files in a certain directory that are a certain number of days old and > removes them from the system (find / -name * -mtime +45 -exec rm -rf {} > \;). I need to port this to a Windows 2000 Server (he shudders as he > says this) and haven't been able to find a command or module that will > do the same search based on the age of the file. Can anyone clue me > into some Windows magic please. You should have a program called find2perl that ships with the standard distribution. find2perl / -name "*" -mtime +45 -exec rm -rf {} \; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Question about writing to file
Richard Noel Fell wrote: > > Here is a subroutine that prints strings to a file. I want the routine > to write strings to the file in the format > Question1:factor(x^2+4*x+3)=(x+3)*(x+1). > However, what is written to file is > Question1:factor(x^2+4*x+3) > =(x+3)*(x+1), that is, > a newline before the = sign. Is there some way of inhibiting this > behavior? > > sub write_questions_and_correct_answers_to_file{ > open In1, ">/home/rfell/tutoring/beaven/webproject/tmp/factor_answers" > or die "Cannot open factor_answers: $!"; > my @qk; # temporary array to hold sorted questions keys > my @ak; # temporary array to hold sorted answer keys > my $qk; # temp variable to hold element of @qk > my $ak; # temp variable to hold element of @ak > @qk=sort(keys %Question_hash); > @ak=sort(keys %Answer_hash); > if ($#qk!=$#ak){ > print "lengths of question hash and answer hash are not equal.\n"; > exit(); > } > else{ > for (my $i=1; $i<=$#qk+1;$i++){ > print In1 > "Question"."$i".":factor$Question_hash{$qk[$i-1]}=$Answer_hash{$ak[$i-1]}\n"; > } > } > close In1; > } sub write_questions_and_correct_answers_to_file { open IN1, ">/home/rfell/tutoring/beaven/webproject/tmp/factor_answers" or die "Cannot open factor_answers: $!"; my @qk = sort keys %Question_hash; my @ak = sort keys %Answer_hash; die "lengths of question hash and answer hash are not equal.\n" if @qk != @ak; chomp %Question_hash; for my $i ( 0 .. $#qk ) { print IN1 "Question$i:factor$Question_hash{$qk[$i]}=$Answer_hash{$ak[$i]}\n"; } close IN1; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
re: unallowed chars
Ok, and where are the recommended characters to disallow? I have tested and I know which characters are going through but I would like to make sure I've included most of the recommended list. >From: Teresa Raymond <[EMAIL PROTECTED]> > >> Where in the Camel or other resource is the list of characters that >> we don't want people to type in. I'm still collecting all the >> resources I lost from my logic board dying. Thanks in advance. > >When testing data you should ALWAYS test whether the string >contains only the allowed characters or is in the allowed format, >never whether it contains some forbidden characters or contains >something that you do not like. > >You may forget something that happens to be special in your case >and you would open a security hole while thinking you are safe. > >While in the life I prefer "what is not forbidden, is allowed" >in programming it should be the oposite. > >Jenda > >=== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz == >There is a reason for living. There must be. I've seen it somewhere. >It's just that in the mess on my table ... and in my brain >I can't find it. > --- me > >-- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] -- --- - Teresa Raymond - - Mariposa Net - - http://www.mariposanet.com - --- -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: code review? bibliographic software script
excuse my curiosity, but what was the purpose in re-implementing the program? you end up with something that runs slower and you need to distribute a runtime engine. unless you plan to extend functionality... On Thursday, March 28, 2002, at 02:52 PM, ERIC Lawson - x52010 wrote: > > I've made a perl script available for downloading, and would appreciate > any code review from anyone so inclined. The script emulates a legacy C > program (1982, named biblio), and is a command-line driven personal > bibliographic manager. Perhaps needless to say, the functions are > anacronistic, and the design goal was simple: make the perl script > function as the C program did. This involved satisfying existing users > who have twenty years of experience with the legacy C program. Thus far, > there've been no complaints from the existing users, although some > departures from exact replication of the C program's look-and-feel are > conspicuous. Notable among the departures, the boolean selection > mechanism is much slower. I would especially appreciate advice on how to > speed up that mechanism. Note, however, that system conditions here, > where the script is in use, militate against my using any other than > modules distributed with a standard, minimal perl distribution, and any > suggestion that I should use such modules will be cheerfully ignored. > > Some commands that will be available through the pbib interface are not > yet fully implemented. I'm waiting to see what, if any, improvements > might be generated by a code review before completing all commands, with > the hope that the remainder of the scripting task will be simplified. > The script is, however, functioning, and in as extensive use as the legacy > C program ever was. An accompanying manual page provides more information > about how to use the script and what to expect from it in terms of > behavior. > > The script and associated files (a manual page in groff, postscript, and > pdf; a manifest and a GPL license file; a small sample database file for > testing purposes) are available via http download, in the form of a > tarred and compressed (gnu compress) file (named pbib-0.1.tgz), from > > http://nsr.bioeng.washington.edu/~eric/index.html > > under either "Contents" or "Projects in Progress". In addition, the same > file is available via anonymous ftp from nsr.bioeng.washington.edu, in the > pub/DOC subdirectory. > > I'm sure the script is a mess. I wrote it while in the process of > relearning perl, which I had some vague acquaintance with in one of its > earlier incarnations. Any and all comments, including, especially, > egregiously abusive ones, will be cheerfully received, although of course > I reserve my right not to reply to what I consider egregious abuse unless > I also find the abuse to have been useful. In the latter case, supposing > a reply from me is appropriate, I will reply as if I didn't notice the > abuse, but instead noticed the usefulness of the comments. > > best, > Eric Lawson > > -- > > James Eric Lawson > Research Publications Editor > National Simulation Resource > > [EMAIL PROTECTED] > > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > > Nothing can exceed the vanity of our existence but the folly of our > pursuits. -- Oliver Goldsmith > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
code review? bibliographic software script
I've made a perl script available for downloading, and would appreciate any code review from anyone so inclined. The script emulates a legacy C program (1982, named biblio), and is a command-line driven personal bibliographic manager. Perhaps needless to say, the functions are anacronistic, and the design goal was simple: make the perl script function as the C program did. This involved satisfying existing users who have twenty years of experience with the legacy C program. Thus far, there've been no complaints from the existing users, although some departures from exact replication of the C program's look-and-feel are conspicuous. Notable among the departures, the boolean selection mechanism is much slower. I would especially appreciate advice on how to speed up that mechanism. Note, however, that system conditions here, where the script is in use, militate against my using any other than modules distributed with a standard, minimal perl distribution, and any suggestion that I should use such modules will be cheerfully ignored. Some commands that will be available through the pbib interface are not yet fully implemented. I'm waiting to see what, if any, improvements might be generated by a code review before completing all commands, with the hope that the remainder of the scripting task will be simplified. The script is, however, functioning, and in as extensive use as the legacy C program ever was. An accompanying manual page provides more information about how to use the script and what to expect from it in terms of behavior. The script and associated files (a manual page in groff, postscript, and pdf; a manifest and a GPL license file; a small sample database file for testing purposes) are available via http download, in the form of a tarred and compressed (gnu compress) file (named pbib-0.1.tgz), from http://nsr.bioeng.washington.edu/~eric/index.html under either "Contents" or "Projects in Progress". In addition, the same file is available via anonymous ftp from nsr.bioeng.washington.edu, in the pub/DOC subdirectory. I'm sure the script is a mess. I wrote it while in the process of relearning perl, which I had some vague acquaintance with in one of its earlier incarnations. Any and all comments, including, especially, egregiously abusive ones, will be cheerfully received, although of course I reserve my right not to reply to what I consider egregious abuse unless I also find the abuse to have been useful. In the latter case, supposing a reply from me is appropriate, I will reply as if I didn't notice the abuse, but instead noticed the usefulness of the comments. best, Eric Lawson -- James Eric Lawson Research Publications Editor National Simulation Resource [EMAIL PROTECTED] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Nothing can exceed the vanity of our existence but the folly of our pursuits. -- Oliver Goldsmith -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: confused about perl and jpg
You're right. I was thinking when I deemed a valid tag. "Agustin Rivera" <[EMAIL PROTECTED]> wrote in message 000d01c1d6a3$f7e83c50$9865fea9@agustinr">news:000d01c1d6a3$f7e83c50$9865fea9@agustinr... > Your html tag is misformatted for starters. > > try > > print " "; > or > print " "; > > I have no idea if the image is actually there, however :) Actually the align=left should be in the main tag or it won't have any effect print " if the picture is in the same directory it should show up [or at the very least you should get a red cross...] Wytch -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: confused about perl and jpg
"Agustin Rivera" <[EMAIL PROTECTED]> wrote in message 000d01c1d6a3$f7e83c50$9865fea9@agustinr">news:000d01c1d6a3$f7e83c50$9865fea9@agustinr... > Your html tag is misformatted for starters. > > try > > print " "; > or > print " "; > > I have no idea if the image is actually there, however :) Actually the align=left should be in the main tag or it won't have any effect print " if the picture is in the same directory it should show up [or at the very least you should get a red cross...] Wytch -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Connecting to DB
ok I declared the vars and now I'm getting a different type of error: DBD::Sybase::db do failed: Server message number=170 severity=15 state=1 line=1 server=WHITETAIL text=Line 1: Incorrect syntax near 'new'. at ../zip.pl line 36. Can't call method "execute" on an undefined value at ./zip.pl line 37. Current code: #!/usr/bin/perl -w use LWP::Simple; use DBI; use strict; my $db="zipcodes"; # my $user="notshown";# Database # my $pass="notshown";# Variables # my $tablename="zips"; # my $insertToDB=1; #Change to zero if you don't want to write to DB my $printToTerm=1; #Change to zero if you don't want results printed to the terminal my $content; my @arr; my @new; my $line; my $count=0; my $dbh; my $action; $_=get("http://zipinfo.com/cgi-local/zipsrch.exe?cnty=cnty&ac=ac&zip=08550";) ;# Get Zipcode Data @arr = /(.*?)<\/td>/g; # Stript Most HTML shift(@arr); #Remove Unwanted shift(@arr); #Data Returned # Strip trailing tag, remove fips code, and Store in array foreach $line(@arr){ $_=$line; /(.*.)<(.)/; if($count != 6){ $new[$count]=$1; ++$count; } } # Insert Data into Database MS SQL SERVER 2K if($insertToDB==1){ $dbh = DBI->connect('DBI:Sybase:server=192.168.0.2', $user, $pass); $dbh->do('INSERT into zips(city,state,county,zip,areacode)VALUES($new[0],$new[1],$new[3],$new[2],$ new[5])'); $action->execute || die print "$! - DB Error"; } # Print to Terminal if($printToTerm==1){ print "@new\n"; } -Original Message- From: Crook, Richard W [mailto:[EMAIL PROTECTED]] Sent: Thursday, March 28, 2002 4:55 PM To: 'Michael Gargiullo'; Beginners Subject: RE: Connecting to DB Looks like you need to declare my $dbh, my $action, my $passwd up where you've declared the others or just turn off strict. To debug your database statement try: die $action to see what the script is sending to the database -Original Message- From: Michael Gargiullo [mailto:[EMAIL PROTECTED]] Sent: Thursday, March 28, 2002 1:31 PM To: Beginners Subject: FW: Connecting to DB OK I have the following array @new which has the following data in it this town this state zipcode county fips (I want discarded) Area code And want to insert these vars into my DB I'm using this code: Old Code
Re: confused about perl and jpg
Your html tag is misformatted for starters. try print " "; or print " "; I have no idea if the image is actually there, however :) Regards, Agustin Rivera Webmaster, Pollstar.com http://www.pollstar.com - Original Message - From: "Jerry Preston" <[EMAIL PROTECTED]> To: "begginners" <[EMAIL PROTECTED]> Sent: Thursday, March 28, 2002 1:40 PM Subject: confused about perl and jpg > Hi!, > > I am trying to display an jpg image: > > print ""; > > But it tells me that the file is not found? What am I missing? > > Thanks, > > Jerry > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Global Variables: 'my' vs 'use vars'
On Thu, 2002-03-28 at 14:55, [EMAIL PROTECTED] wrote: > Hello, All: > > I've never been very good at scoping so it it's no surprise that this > confuses me: > > When declaring variables at the beginning of a script, what is the > difference between 'my' and 'use vars'? > > -- > Eric P. > Los Gatos, CA The big difference is that 'use vars;' doesn't produce warnings when used with Getopt::Std . I think it boils down to the fact that use vars is compiler directive (pragma) that prevents specific warnings from being issued and my is a function that declares a local variable. Variables get declared when they are used by default in Perl (unlike some languages like C). This can be a good thing if you only need 10 lines of code and don't want to waste time typing; however, it is a very bad thing in larger programs (ie you meant to type @commands but typed @command instead and it simple gets created). This is why they added warnings to tell you about one use variables and various other warnings. But that was not enough; some programmers still had tons of errors, so they added 'use strict;' which forces you to do some things that just make sense for large projects. Also note that use vars has been superseded by the our command in later versions of perl (5.6 and up). NOTE: The functionality provided by this pragma has been superseded by "our" declarations, available in Perl v5.6.0 or later. See the our entry in the perlfunc manpage. -- Today is Boomtime the 14th day of Discord in the YOLD 3168 This statement is false. Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Connecting to DB
Looks like you need to declare my $dbh, my $action, my $passwd up where you've declared the others or just turn off strict. To debug your database statement try: die $action to see what the script is sending to the database -Original Message- From: Michael Gargiullo [mailto:[EMAIL PROTECTED]] Sent: Thursday, March 28, 2002 1:31 PM To: Beginners Subject: FW: Connecting to DB OK I have the following array @new which has the following data in it this town this state zipcode county fips (I want discarded) Area code And want to insert these vars into my DB I'm using this code: #!/usr/bin/perl -w use LWP::Simple; use DBI; use strict; my $db="zipcodes"; # my $user="notshown";# Database # my $pass="notshown";# Variables # my $tablename="zips"; # my $insertToDB=1; #Change to zero if you don't want to write to DB my $printToTerm=1; #Change to zero if you don't want results printed to the terminal my $content; my @arr; my @new; my $line; my $count=0; $_=get("http://zipinfo.com/cgi-local/zipsrch.exe?cnty=cnty&ac=ac&zip=08550";) ;# Get Zipcode Data @arr = /(.*?)<\/td>/g; # Stript Most HTML shift(@arr); #Remove Unwanted shift(@arr); #Data Returned # Strip trailing tag, remove fips code, and Store in array foreach $line(@arr){ $_=$line; /(.*.)<(.)/; if($count != 6){ $new[$count]=$1; ++$count; } } # Insert Data into Database MS SQL SERVER 2K if($insertToDB==1){ $dbh = DBI->connect('DBI:Sybase:server=192.168.0.2', $user,$passwd); $dbh->do(INSERT into $tablename(city,state,county,zip,areacode)VALUES($new[0],$new[1],$new[3],$ne w[2],$new[5]); $action->execute; } # Print to Terminal if($printToTerm==1){ print "@new\n"; } These are the errors I'm receiving: Global symbol "$dbh" requires explicit package name at ./zip.pl line 32. Global symbol "$passwd" requires explicit package name at ./zip.pl line 32. Global symbol "$dbh" requires explicit package name at ./zip.pl line 33. Global symbol "$action" requires explicit package name at ./zip.pl line 34. Execution of ./zip.pl aborted due to compilation errors. [mike@viper mike]$ ./zip.pl Global symbol "$dbh" requires explicit package name at ./zip.pl line 32. Global symbol "$passwd" requires explicit package name at ./zip.pl line 32. Global symbol "$dbh" requires explicit package name at ./zip.pl line 33. syntax error at ./zip.pl line 33, near "$tablename(" Bareword found where operator expected at ./zip.pl line 33, near ")VALUES" (Missing operator before VALUES?) Global symbol "$action" requires explicit package name at ./zip.pl line 34. Execution of ./zip.pl aborted due to compilation errors. I know that I can connect to the DB. I can connect using this script: #!/usr/bin/perl use DBI; $user='notshown'; $passwd='notshown'; $dbh = DBI->connect('DBI:Sybase:server=192.168.0.2', $user, $passwd); $dbh->do("use Northwind"); $action = $dbh->prepare("sp_help"); $action->execute; $rows = $action->rows; print "rows is $rows\n"; while(@first = $action->fetchrow_array){ foreach $field (@first){ print "$field\t"; } print "\n"; } exit(0); Any light you can shed on this would be greatly appriciated. Thank you Mike ___ Composed with Pine 4.2.1 FACT: George Washington was actually the 8th President of the United States, but the first under our current constitution. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re:client side authentication link
Someone mailed me off list and pointed out that the url I posted had been wrapped. I also noticed that I had given a url I had bookmarked which is a mirror of the document, not the official site. There is some other related material there and postscript and html versions in addition to the pdf. You can find it at: http://cookies.lcs.mit.edu/ Sorry for posting twice, but I think this is worth reading if you are doing user authentication, and it's pretty entertaining as well. Tagore Smith -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
confused about perl and jpg
Hi!, I am trying to display an jpg image: print ""; But it tells me that the file is not found? What am I missing? Thanks, Jerry -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
FW: Connecting to DB
OK I have the following array @new which has the following data in it this town this state zipcode county fips (I want discarded) Area code And want to insert these vars into my DB I'm using this code: #!/usr/bin/perl -w use LWP::Simple; use DBI; use strict; my $db="zipcodes"; # my $user="notshown";# Database # my $pass="notshown";# Variables # my $tablename="zips"; # my $insertToDB=1; #Change to zero if you don't want to write to DB my $printToTerm=1; #Change to zero if you don't want results printed to the terminal my $content; my @arr; my @new; my $line; my $count=0; $_=get("http://zipinfo.com/cgi-local/zipsrch.exe?cnty=cnty&ac=ac&zip=08550";) ;# Get Zipcode Data @arr = /(.*?)<\/td>/g; # Stript Most HTML shift(@arr); #Remove Unwanted shift(@arr); #Data Returned # Strip trailing tag, remove fips code, and Store in array foreach $line(@arr){ $_=$line; /(.*.)<(.)/; if($count != 6){ $new[$count]=$1; ++$count; } } # Insert Data into Database MS SQL SERVER 2K if($insertToDB==1){ $dbh = DBI->connect('DBI:Sybase:server=192.168.0.2', $user,$passwd); $dbh->do(INSERT into $tablename(city,state,county,zip,areacode)VALUES($new[0],$new[1],$new[3],$ne w[2],$new[5]); $action->execute; } # Print to Terminal if($printToTerm==1){ print "@new\n"; } These are the errors I'm receiving: Global symbol "$dbh" requires explicit package name at ./zip.pl line 32. Global symbol "$passwd" requires explicit package name at ./zip.pl line 32. Global symbol "$dbh" requires explicit package name at ./zip.pl line 33. Global symbol "$action" requires explicit package name at ./zip.pl line 34. Execution of ./zip.pl aborted due to compilation errors. [mike@viper mike]$ ./zip.pl Global symbol "$dbh" requires explicit package name at ./zip.pl line 32. Global symbol "$passwd" requires explicit package name at ./zip.pl line 32. Global symbol "$dbh" requires explicit package name at ./zip.pl line 33. syntax error at ./zip.pl line 33, near "$tablename(" Bareword found where operator expected at ./zip.pl line 33, near ")VALUES" (Missing operator before VALUES?) Global symbol "$action" requires explicit package name at ./zip.pl line 34. Execution of ./zip.pl aborted due to compilation errors. I know that I can connect to the DB. I can connect using this script: #!/usr/bin/perl use DBI; $user='notshown'; $passwd='notshown'; $dbh = DBI->connect('DBI:Sybase:server=192.168.0.2', $user, $passwd); $dbh->do("use Northwind"); $action = $dbh->prepare("sp_help"); $action->execute; $rows = $action->rows; print "rows is $rows\n"; while(@first = $action->fetchrow_array){ foreach $field (@first){ print "$field\t"; } print "\n"; } exit(0); Any light you can shed on this would be greatly appriciated. Thank you Mike ___ Composed with Pine 4.2.1 FACT: George Washington was actually the 8th President of the United States, but the first under our current constitution. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
SSL and IMAP
I'm using Mail::IMAPClient to write a mail filter via IMAP. I'd like to connect to the server using SSL. The instructions in the man page don't help me: $imap=Mail::IMAPClient->new(User => $user, Password => $pass, Server => $host); # blah blah blah (doc's blah blah blah, not mine!) $imap->Socket($ssl); Can someone give me a pointer in the right direction? I assume I need to also use an SSL module (IO-Socket-SSL?), but some pointers to fill in that # blah blah blah would be terrific. Also, if there's a better module than Mail::IMAPClient to do IMAP and SSL, that would be great, too. Pete -- Those responsible for the signature have been sacked. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Global Variables: 'my' vs 'use vars'
Hello, All: I've never been very good at scoping so it it's no surprise that this confuses me: When declaring variables at the beginning of a script, what is the difference between 'my' and 'use vars'? -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: context of function calls
remember when calling a subroutine with & prepended, prototypes are never looked at. > -Original Message- > From: Peter Scott [mailto:[EMAIL PROTECTED]] > Sent: Thursday, March 28, 2002 3:32 PM > To: Dave Storrs; Perl 6 Beginners list > Subject: Re: context of function calls > > > > >Perl 6 Beginners list <[EMAIL PROTECTED]> > ^^^ ahem? > > At 11:13 AM 3/28/02 -0800, Dave Storrs wrote: > >Executive summary: It looks like, no matter what context > foo() is called > >in, its arguments are always evaluated in list context. Is > this correct? > > Unless a prototype overrides it, yes. For instance, sprintf has an > implicit prototype that says it expects a scalar as its first > argument: > > % perl -le 'sub foo{ print wantarray ? "list" : "scalar" }; > sprintf(foo)' > scalar > > >I had always understood that: > > - a function's arguments were evaluated in the same > context as the > >context of the function (hmm...actually, thinking about it, > this seems > >like it can't be right. Is it simply always LIST, or can it vary?) > > For builtins, look at the signature in perlfunc. For your > own functions, > use a prototype to change it from LIST. In general, you need > a good reason > to do this. > -- > Peter Scott > Pacific Systems Design Technologies > http://www.perldebugged.com > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: context of function calls
>Perl 6 Beginners list <[EMAIL PROTECTED]> ^^^ ahem? At 11:13 AM 3/28/02 -0800, Dave Storrs wrote: >Executive summary: It looks like, no matter what context foo() is called >in, its arguments are always evaluated in list context. Is this correct? Unless a prototype overrides it, yes. For instance, sprintf has an implicit prototype that says it expects a scalar as its first argument: % perl -le 'sub foo{ print wantarray ? "list" : "scalar" }; sprintf(foo)' scalar >I had always understood that: > - a function's arguments were evaluated in the same context as the >context of the function (hmm...actually, thinking about it, this seems >like it can't be right. Is it simply always LIST, or can it vary?) For builtins, look at the signature in perlfunc. For your own functions, use a prototype to change it from LIST. In general, you need a good reason to do this. -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Testing for filehandles
On Thu, 28 Mar 2002, Bob Showalter wrote: > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] > > Thanks, Bob! After reading the IO::Handle man page, I decided > > to distill this approach a bit further: > > > > print F if fileno(F); > > Of course, that's even simpler! Just to be nitpicky, the test maybe > should be > >defined(fileno(F)) > > Since 0 is a valid file number (STDIN). So, technically, I should be testing for "definedness" instead of "truth". i.e., From `perldoc -f fileno`: Returns the file descriptor for a filehandle, or undefined if the filehandle is not open. > If you're just going to do the test on the print statement, it's > not accomplishing all that much, since the print() will silently > fail if the file isn't open. But a test like this would be useful > if you want to avoid doing a lengthy operation to generate the > data to be printed. Printing to a non-existant filehandle (while using the -w switch) generates a warning message: Filehandle main::FOO never opened at... -- Eric P. Los Gatos, CA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: using search backreferences in a variable
On Mar 28, Bryan R Harris said: >- Why is the \1, \2, etc. syntax obsolete? The one thing I love about >regular expressions is that I can use them within text editors (nedit, >textpad, bbedit), but none of these support the $1 notation in the replace >string. Why aren't re's consistent between perl and text editors? \1 and \2 are to be used on the LEFT-HAND side of a regex; on the RIGHT-HAND side, you should use $1 and $2 to remove any ambiguity, because \1 can ALSO mean chr(1). >- What does the "qr" tag do? qr// makes a Regexp object that is a compiled regular expression. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** what does y/// stand for? why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: using search backreferences in a variable
Jeff, David, Nikola-I obviously haven't been doing this long, but I already love perl. Thanks for the tips. A couple quick questions: - Why is the \1, \2, etc. syntax obsolete? The one thing I love about regular expressions is that I can use them within text editors (nedit, textpad, bbedit), but none of these support the $1 notation in the replace string. Why aren't re's consistent between perl and text editors? - What does the "qr" tag do? Thanks again. - Bryan __ \1 is obsolete. try $1 and you also have use the /ee and fix your $replace for the /ee read perldoc perlre $match = qr/cat(\d+)/; $replace = '$1. "dog"'; $_ = "cat15"; s/$match/$replace/gee; print $_, "\n"; # prints --> 15dog > -Original Message- > From: Bryan R Harris [mailto:[EMAIL PROTECTED]] > Sent: Thursday, March 28, 2002 10:46 AM > To: Beginners Perl Mailing List > Subject: using search backreferences in a variable > > > > Why does this segment not work properly? > > $match = "cat(\d+)"; > $replace = "\1dog"; > $_ = "cat15"; > s/$match/$replace/g; > print $_; # prints --> \1dog > > Any ideas? > > TIA. > > - B > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Creating a Unique Key
Nikola Janceski wrote: > Uh... exactly what are you going to be using it for? > You might want to check out the function call crypt() in the perlfunc pages. > > > -Original Message- > > From: Gregory Matthews [mailto:[EMAIL PROTECTED]] > > Sent: Thursday, March 28, 2002 2:30 PM > > To: [EMAIL PROTECTED] > > Subject: Creating a Unique Key > > > > > > What is the best way to create a unique, almost impossible to guess, > > KEY, i.e., ftu880oli88UI8flpq, which can in turn be used as part of a > > security string, i.e., username: ftu880oli88UI8flpq ? Check out: http://www.cs.cornell.edu/People/egs/syslunch-spring02/syslunchsp02/webauth_ tr.pdf It details how the authors weakened or broke the authentication mechanisms of a number of prominent e-commerce sites, and gives background information on doing authentication well. One of the things it talks about is the weakness of the authentication scheme at the Wall Street Journal's web page caused by a misunderstanding of how crypt works. They do propose a stronger authentication scheme. Tagore Smith -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Find Files Based on Age
Write a really cool subroutine for File::Find or I can give you an example to work from I recommend perl V5.6.1+ if you are going to use File::Find > -Original Message- > From: Scott Burks [mailto:[EMAIL PROTECTED]] > Sent: Thursday, March 28, 2002 2:56 PM > To: [EMAIL PROTECTED] > Subject: Find Files Based on Age > > > This might be simple, but I haven't found a solution yet. I have a > script that I use on our Unix boxes that uses 'find' to get a list of > files in a certain directory that are a certain number of days old and > removes them from the system (find / -name * -mtime +45 -exec > rm -rf {} > \;). I need to port this to a Windows 2000 Server (he shudders as he > says this) and haven't been able to find a command or module that will > do the same search based on the age of the file. Can anyone clue me > into some Windows magic please. > > Scott Burks > Systems Administrator > Trust Company of America > > The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Find Files Based on Age
This might be simple, but I haven't found a solution yet. I have a script that I use on our Unix boxes that uses 'find' to get a list of files in a certain directory that are a certain number of days old and removes them from the system (find / -name * -mtime +45 -exec rm -rf {} \;). I need to port this to a Windows 2000 Server (he shudders as he says this) and haven't been able to find a command or module that will do the same search based on the age of the file. Can anyone clue me into some Windows magic please. Scott Burks Systems Administrator Trust Company of America
Re: Creating a Unique Key
uuidgen can create a nearly 100% unique key, but if the attackers has access to the machine it was generated on and knowledge of the approximate time the key was generated then it is fairly easy to guess/reverse engineer the key. You may want to look into using a very large prime number or some such. Probably the best thing to do would be to generate a key pair using ssh2-keygen. On Thu, 2002-03-28 at 14:30, Gregory Matthews wrote: > What is the best way to create a unique, almost impossible to guess, > KEY, i.e., ftu880oli88UI8flpq, which can in turn be used as part of a > security string, i.e., username: ftu880oli88UI8flpq ? > > Thanks in advance. > > Gregory -- Today is Boomtime the 14th day of Discord in the YOLD 3168 Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Creating a Unique Key
Uh... exactly what are you going to be using it for? You might want to check out the function call crypt() in the perlfunc pages. > -Original Message- > From: Gregory Matthews [mailto:[EMAIL PROTECTED]] > Sent: Thursday, March 28, 2002 2:30 PM > To: [EMAIL PROTECTED] > Subject: Creating a Unique Key > > > What is the best way to create a unique, almost impossible to guess, > KEY, i.e., ftu880oli88UI8flpq, which can in turn be used as part of a > security string, i.e., username: ftu880oli88UI8flpq ? > > Thanks in advance. > > Gregory > The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Creating a Unique Key
What is the best way to create a unique, almost impossible to guess, KEY, i.e., ftu880oli88UI8flpq, which can in turn be used as part of a security string, i.e., username: ftu880oli88UI8flpq ? Thanks in advance. Gregory
html to perl vars
Hi!, How does one convert html: to a Perl? $value_1 = T1; Thanks, Jerry -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Question about writing to file
Try removing the newline at the end of your question with a call to chomp. else{ for (my $i=1; $i<=$#qk+1;$i++){ chomp ($Question_hash{$qk[$i-1]}); print In1 "Question"."$i".":factor$Question_hash{$qk[$i-1]}=$Answer_hash{$ak[$i-1]}\n"; } >Here is a subroutine that prints strings to a file. I want the routine >to write strings to the file in the format >Question1:factor(x^2+4*x+3)=(x+3)*(x+1). >However, what is written to file is >Question1:factor(x^2+4*x+3) >=(x+3)*(x+1), that is, >a newline before the = sign. Is there some way of inhibiting this >behavior? >Thanks, >Dick Fell > > > >sub write_questions_and_correct_answers_to_file{ >open In1, ">/home/rfell/tutoring/beaven/webproject/tmp/factor_answers" >or die "Cannot open factor_answers: $!"; >my @qk; # temporary array to hold sorted questions keys >my @ak; # temporary array to hold sorted answer keys >my $qk; # temp variable to hold element of @qk >my $ak; # temp variable to hold element of @ak >@qk=sort(keys %Question_hash); >@ak=sort(keys %Answer_hash); >if ($#qk!=$#ak){ >print "lengths of question hash and answer hash are not equal.\n"; >exit(); >} >else{ > for (my $i=1; $i<=$#qk+1;$i++){ >print In1 >"Question"."$i".":factor$Question_hash{$qk[$i-1]}=$Answer_hash{$ak[$i-1]}\n"; >} >} >close In1; >} > >-- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] -- Hans E. E. Holtan Graduate Student UC Berkeley-Department of Plant and Microbial Biology Plant Gene Expression Center 800 Buchanan Street Albany, California 94710 U. S. A. Phone: (510) 559-5922 FAX: (510) 559-6089 [EMAIL PROTECTED] _ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
context of function calls
Hey folks, Executive summary: It looks like, no matter what context foo() is called in, its arguments are always evaluated in list context. Is this correct? I had always understood that: - a function's arguments were evaluated in the same context as the context of the function (hmm...actually, thinking about it, this seems like it can't be right. Is it simply always LIST, or can it vary?) - a function's context propogated downwards into any functions it calls. Full version: I thought I had a pretty good handle on the whole concept of context, but I've tripped over it several times recently, so I set up a test: #!/usr/local/bin/perl -w use strict; $\ = "\n"; {print "\$x = bar()"; my $x = bar(); foo($x);} {print "\@x = bar()"; my @x = bar(); foo(@x);} {print "\$x = foo( bar() )"; my $x = foo( bar() );} {print "\@x = foo( bar() )"; my @x = foo( bar() );} {print "foo( bar() )"; foo( bar() );} sub foo { while (@_) { my $parm = shift; for ($parm) { unless (defined) { $parm = 'VOID'; last; } $parm = $parm ? 'LIST' : 'SCALAR'; } print "\t$parm"; } } sub bar { return wantarray(); } print "Done."; __END__ This outputs what context bar() is called in. I expected this to output the following: ### EXPECTED OUTPUT. THIS IS NOT WHAT IT GIVES $x = bar() SCALAR @x = bar() LIST $x = foo( bar() ) SCALAR @x = foo( bar() ) LIST foo( bar() ) VOID Done. ### /EXPECTED OUTPUT. Instead, I get this: $x = bar() SCALAR @x = bar() LIST $x = foo( bar() ) LIST @x = foo( bar() ) LIST foo( bar() ) LIST Done. Any comments, anyone? Dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Question about writing to file
There must be something else going on. Tried just going to the screen and it worked like one would expect. Can you show the list a snippet of your code? What system are you on? What perl? Wags ;) -Original Message- From: richard noel fell [mailto:[EMAIL PROTECTED]] Sent: Thursday, March 28, 2002 11:26 To: [EMAIL PROTECTED] Subject: Question about writing to file Here is a subroutine that prints strings to a file. I want the routine to write strings to the file in the format Question1:factor(x^2+4*x+3)=(x+3)*(x+1). However, what is written to file is Question1:factor(x^2+4*x+3) =(x+3)*(x+1), that is, a newline before the = sign. Is there some way of inhibiting this behavior? Thanks, Dick Fell sub write_questions_and_correct_answers_to_file{ open In1, ">/home/rfell/tutoring/beaven/webproject/tmp/factor_answers" or die "Cannot open factor_answers: $!"; my @qk; # temporary array to hold sorted questions keys my @ak; # temporary array to hold sorted answer keys my $qk; # temp variable to hold element of @qk my $ak; # temp variable to hold element of @ak @qk=sort(keys %Question_hash); @ak=sort(keys %Answer_hash); if ($#qk!=$#ak){ print "lengths of question hash and answer hash are not equal.\n"; exit(); } else{ for (my $i=1; $i<=$#qk+1;$i++){ print In1 "Question"."$i".":factor$Question_hash{$qk[$i-1]}=$Answer_hash{$ak[$i-1]}\n"; } } close In1; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Question about writing to file
Here is a subroutine that prints strings to a file. I want the routine to write strings to the file in the format Question1:factor(x^2+4*x+3)=(x+3)*(x+1). However, what is written to file is Question1:factor(x^2+4*x+3) =(x+3)*(x+1), that is, a newline before the = sign. Is there some way of inhibiting this behavior? Thanks, Dick Fell sub write_questions_and_correct_answers_to_file{ open In1, ">/home/rfell/tutoring/beaven/webproject/tmp/factor_answers" or die "Cannot open factor_answers: $!"; my @qk; # temporary array to hold sorted questions keys my @ak; # temporary array to hold sorted answer keys my $qk; # temp variable to hold element of @qk my $ak; # temp variable to hold element of @ak @qk=sort(keys %Question_hash); @ak=sort(keys %Answer_hash); if ($#qk!=$#ak){ print "lengths of question hash and answer hash are not equal.\n"; exit(); } else{ for (my $i=1; $i<=$#qk+1;$i++){ print In1 "Question"."$i".":factor$Question_hash{$qk[$i-1]}=$Answer_hash{$ak[$i-1]}\n"; } } close In1; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: thanks for the response yesterday , but I still dont get it ...T rying not to add dup names in DB
On Thu, 2002-03-28 at 12:26, FLAHERTY, JIM-CONT wrote: > I made the column testname unique . But I did quite understand how to change > to query syntax. > Stephen told me to add where clause "Where IDENTIFIER NOT IN ( SELECT > IDENTIFIER FROM TABLE)" > > I dont get what he means .. I am new to perl . First you need to create a separation in your head: SQL and Perl. Perl is a scripting language that happens to have a module called DBI that lets you talk to databases in SQL (Structured Query Language). Your problem lies not within Perl, but within your understanding of SQL and consequently relational databases. > > > > the table > > show columns from phistory; > +---+-+--+-+-++ > | Field | Type| Null | Key | Default | Extra | > +---+-+--+-+-++ > | num | int(4) | | PRI | NULL| auto_increment | > | testname | varchar(60) | YES | MUL | NULL|| > | numpeople | int(6) | YES | | NULL|| > | numtimes | int(6) | YES | | NULL|| > | average | float | YES | | NULL|| > +---+-+--+-+-++ > 5 rows in set (0.00 sec) #the follow query first gets a list of all testnames in the phistory #table and then finds all entries in testhistory that do not match #at least one of the testnames in the list gotten from phistory. my $sth = $dbh->prepare( #this is the identifier #he talked about # || # \/ "select distinct testname from testhistory where testname not in (select distinct testname from phistory)" ) or die " unable to prepare query:" . $dbh->errstr; $sth->execute or die " unable to execute query:" . $dbh->errstr; foreach $row (@{$sth->fetchall_arrayref}) { my($tname) = @$row; #$dbh->quote knows how to quote character strings for #the database it is connected to #NOTE: this declaration of $sth masks the earlier one #this $sth only lives inside the foreach loop my $sth = $dbh->prepare( 'insert into phistory (testname) values (' . $dbh->quote($tname) . ')') or die " unable to prepare query:" . $dbh->errstr; $sth->execute or die " unable to execute query:" . $dbh->errstr; $sth->finish; } $sth->finish; -- Today is Boomtime the 14th day of Discord in the YOLD 3168 Keep the Lasagna flying! Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: random word from array
While you're looking up "my", look up 'use strict'. It'll be much easier on you if you get used to using it now than if you have to go back over all of your old scripts. -Original Message- From: Wytch [mailto:[EMAIL PROTECTED]] Sent: Thursday, March 28, 2002 3:26 AM To: [EMAIL PROTECTED] Subject: Re: random word from array "Randal L. Schwartz" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > That's correct, but if you have a very very very old Perl, you'll need > to add "srand;" at the beginning of your program. Do it just once, > though. That was one of the first things I tried - but I think my Perl is pretty up to date [I only downloaded it the day before yesterdaylol] anyhoo - it didn't make any difference. > The normal idiom is: > > my $one_of_many = $many[rand @many]; I keep seeing this "my $var" hmmm I understand what it is but not really when to use it and when not - *decides to go do some reading up on *my* and experiment* Wytch -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This email may contain confidential and privileged material for the sole use of the intended recipient. If you are not the intended recipient, please contact the sender and delete all copies. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: counter script and chmod 755
From: Bill Bartok <[EMAIL PROTECTED]> > I am putting a counter on a website for the first time. I undstand that > because the server is Unix that I will need to se permission for the > counter. > > I believe this can be done within the Perl script using the line: > > chmod (0755, "counter.cgi"); > > right within the counter.cgi script itself. No. It's too late. The permissions ahve to be set before you try to execute the script. How to do that depends on your access to the server. If you have a telnet access (or SSH or whatever, simply something where you can enter commands) you can use chmod 0755 counter.cgi on the prompt (command line). Or you can have a script that does this for you. Or ... Jenda === [EMAIL PROTECTED] == http://Jenda.Krynicky.cz == There is a reason for living. There must be. I've seen it somewhere. It's just that in the mess on my table ... and in my brain I can't find it. --- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: counter script and chmod 755
> I am putting a counter on a website for the first time. I > undstand that because the server is Unix that I will need to > se permission for the counter. > > I believe this can be done within the Perl script using the line: > > chmod (0755, "counter.cgi"); > > right within the counter.cgi script itself. > > Is this correct and where in the script should it be placed. There is a much easier way to do that if you have shell access to the server. You can type chmod 755 counter.cgi at the command prompt. I'm not sure if you would be able to set the permissions from within the script, I've never tried that. If you try all of your options and nothing's working, please let us know what you've tried and what errors you get. Hope that helps, -dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
thanks for the response yesterday , but I still dont get it ... Trying not to add dup names in DB
I made the column testname unique . But I did quite understand how to change to query syntax. Stephen told me to add where clause "Where IDENTIFIER NOT IN ( SELECT IDENTIFIER FROM TABLE)" I dont get what he means .. I am new to perl . the table show columns from phistory; +---+-+--+-+-++ | Field | Type| Null | Key | Default | Extra | +---+-+--+-+-++ | num | int(4) | | PRI | NULL| auto_increment | | testname | varchar(60) | YES | MUL | NULL|| | numpeople | int(6) | YES | | NULL|| | numtimes | int(6) | YES | | NULL|| | average | float | YES | | NULL|| +---+-+--+-+-++ 5 rows in set (0.00 sec) mysql> CODE my $sth1 = $dbh -> prepare("select distinct testname from testhistory"); $sth1 -> execute or die " unable to execute query "; #$sth1 -> finish; my $array_ref1 = $sth1->fetchall_arrayref(); foreach $row(@$array_ref1) { my($tname) = @$row; my $sth2 = $dbh -> prepare("insert into phistory(testname)values('$tname')"); $sth2 -> execute or die " unable to execute query "; #$sth1 -> finish; } thanks Jim
Re: unallowed characters
From: Teresa Raymond <[EMAIL PROTECTED]> > Where in the Camel or other resource is the list of characters that > we don't want people to type in. I'm still collecting all the > resources I lost from my logic board dying. Thanks in advance. When testing data you should ALWAYS test whether the string contains only the allowed characters or is in the allowed format, never whether it contains some forbidden characters or contains something that you do not like. You may forget something that happens to be special in your case and you would open a security hole while thinking you are safe. While in the life I prefer "what is not forbidden, is allowed" in programming it should be the oposite. Jenda === [EMAIL PROTECTED] == http://Jenda.Krynicky.cz == There is a reason for living. There must be. I've seen it somewhere. It's just that in the mess on my table ... and in my brain I can't find it. --- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Array question...
On Thu, 2002-03-28 at 08:54, Michael D. Risser wrote: > OK here's the problem: > > I have an array that may or may not have been assigned to, if it has been > assigned to I need to do one thing, otherwise I need to do something else. > > I've tried many variations, but I'm having trouble determining if it has been > assigned to. > > if(undef @myArray) { > # Do thing1 > } elsif(!undef @myArray) { > # Do thing2 > } > > and > > if ($myArray[0] ne "") { > # thing1 > } else { > # thing2 > } > > as well as a few other variations. Printing out the array BEFORE the if block > shows nothing in the array, yet it does thing1. > > After trying many different methods, I am totally lost, please help me! > > TIA Since an array returns the number of elements it contains when it is evaluated in scalar context why don't you just say: #0 is false, non-zero is true so if @myArray has data #then we do something otherwise we do something else if (@MyArray) { local($") = ','; #make the interpolation of @MyArray use ','s print "my \@MyArray = (@MyArray);\n"; } else { print "my \@MyArray;\n"; } -- Today is Boomtime the 14th day of Discord in the YOLD 3168 You are what you see. Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Array question...
On Thursday 28 March 2002 08:54 am, you wrote: > OK here's the problem: > > I have an array that may or may not have been assigned to, if it has been > assigned to I need to do one thing, otherwise I need to do something else. > > I've tried many variations, but I'm having trouble determining if it has > been assigned to. > > if(undef @myArray) { > # Do thing1 > } elsif(!undef @myArray) { > # Do thing2 > } > > and > > if ($myArray[0] ne "") { > # thing1 > } else { > # thing2 > } > > as well as a few other variations. Printing out the array BEFORE the if > block shows nothing in the array, yet it does thing1. OOPS I meant it does thing2 :-) > After trying many different methods, I am totally lost, please help me! > > TIA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
counter script and chmod 755
I am putting a counter on a website for the first time. I undstand that because the server is Unix that I will need to se permission for the counter. I believe this can be done within the Perl script using the line: chmod (0755, "counter.cgi"); right within the counter.cgi script itself. Is this correct and where in the script should it be placed. Thanks for any advice. Bill Bartok -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Array question...
try if (defined @array) { # do something } else { # It's not been created, do something else } HTH John -Original Message- From: Michael D. Risser [mailto:[EMAIL PROTECTED]] Sent: 28 March 2002 13:55 To: [EMAIL PROTECTED] Subject: Array question... OK here's the problem: I have an array that may or may not have been assigned to, if it has been assigned to I need to do one thing, otherwise I need to do something else. I've tried many variations, but I'm having trouble determining if it has been assigned to. if(undef @myArray) { # Do thing1 } elsif(!undef @myArray) { # Do thing2 } and if ($myArray[0] ne "") { # thing1 } else { # thing2 } as well as a few other variations. Printing out the array BEFORE the if block shows nothing in the array, yet it does thing1. After trying many different methods, I am totally lost, please help me! TIA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --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. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Array question...
OK here's the problem: I have an array that may or may not have been assigned to, if it has been assigned to I need to do one thing, otherwise I need to do something else. I've tried many variations, but I'm having trouble determining if it has been assigned to. if(undef @myArray) { # Do thing1 } elsif(!undef @myArray) { # Do thing2 } and if ($myArray[0] ne "") { # thing1 } else { # thing2 } as well as a few other variations. Printing out the array BEFORE the if block shows nothing in the array, yet it does thing1. After trying many different methods, I am totally lost, please help me! TIA -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Batch creation of thumbnails
> "Gary" == Gary Stainburn <[EMAIL PROTECTED]> writes: >> my @names = @ARGV ? @ARGV : grep { -f and -B } <*>; Gary> I read this to say, if filenames passed use them otherwise do the whole of Gary> the current directory. I believe that the grep takes the list provided by Gary> <*> performs the -f and -B filters on the list and assigns the result to Gary> @names. Am I correct, and what does the -f and -B do? Yes. It says "is the name both a file and a binary-content file?". >> undef @$im; Gary> This one confused me. I'm assuming that it's resetting the variables used by Gary> the object $im, while keeping the object intact. If this is correct, is this Gary> something specific to Image::Magick, or can a similar method work with most Gary> objects? No, this is specific to I::M. I wonder why it's necessary. In fact, I wonder why *most* things in the clunky interface of I::M are necessary. :) Gary> If $im->Read fails, it assigns an error value to $ret, which in turn returns Gary> true. Only if the assignment is true, will the second half of the 'and' Gary> execute giving the warning and skipping Bingo! -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
beginners@perl.org
good info.. but this doesn't look like a method call. I prefer prototypes for modules that I write for internal use at my company, especially when I don't feel like explaining to 60 people everytime why thier code doesn't work, when they forget to pass an extra argument. > -Original Message- > From: Chas Owens [mailto:[EMAIL PROTECTED]] > Sent: Thursday, March 28, 2002 11:03 AM > To: [EMAIL PROTECTED] > Subject: RE: && > > > On Thu, 2002-03-28 at 10:50, Nikola Janceski wrote: > > There in lies your problem.. you are not passing to the subroutine > > correctly. > > > > try declaring your sub like so: > > sub extract_data (\@\@\@){ > > but if you do this don't call extract_data with & > > use > > extract_data(@datum, @seminare, @staedte); > > > > or pass the ref of the arrays: > > extract_data(\@datum, \@seminare, \@staedte); > > Passing as refs appears to be the preferred method. Subroutine > prototypes are flaky and don't work properly with OO based Perl > (prototypes can only handle stuff at compile time, while OO > method calls > happen at runtime). > > > > > > > > -Original Message- > > > From: [EMAIL PROTECTED] > > > [mailto:[EMAIL PROTECTED]] > > > Sent: Thursday, March 28, 2002 10:39 AM > > > To: Chas Owens > > > Cc: [EMAIL PROTECTED] > > > Subject: Re: && > > > > > > > > > Hi Chas, > > > > > > > > > thanks for your reply. > > > The code was the simplified code of a subroutine (below). > The Data > > > originates from a Webformula and is passed on to the > Subroutine like > > > > > > snippet > > > &extract_data(@datum, @seminare, @staedte); > > > .. > > > .. > > > .. > > > > > > sub extract_data { > > > my $dates = shift; > > > my $themes = shift; > > > my $cities = shift; > > > my @dates = split /\s+/, "$dates"; > > > my @themes = split /\s+/, "$themes"; > > > my @cities = split /\s+/, "$cities"; > > > if(@dates && !@themes && !@cities) { > > > my $date_count = @dates; > > > if($date_count > 1) { > > > $sth_between = $dbh->prepare( qq{SELECT * > FROM termine > > > WHERE beginn BETWEEN ? and ?}); > > > $sth_between->execute($dates[0],$dates[1]); > > > my $result = $sth_between->fetchrow_hashref(); > > > if($result){ > > > print $form->p("$result->{beginn}"); > > > #print out rest of fields > > > } > > > } > > > else { > > > $sth_exact = $dbh->prepare(qq {SELECT * FROM > > > termine WHERE > > > beginn < ? ORDER BY beginn ASC}); > > > $sth_exact->execute($dates[0]); > > > my $result = $sth_exact->fetchrow_hashref(); > > > if($result){ > > > while($result){ > > > print $form->p("$result->{beginn}"); > > > #print out rest of fields > > > } > > > } > > > else{ > > > print $form->p("Tut mir leid nichts > gefunden"); > > > } > > > } > > > } > > > #here should be all the other if else loop seven in total > > > each printing > > > #out search results depending on which array or which > combination of > > > #arrays contains data > > > > > > > > > } > > > Marcus > > > > > > > > > > > > -- > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > -- > -- > > > > The views and opinions expressed in this email message are > the sender's > > own, and do not necessarily represent the views and > opinions of Summit > > Systems Inc. > > > > > > -- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > -- > Today is Boomtime the 14th day of Discord in the YOLD 3168 > Umlaut Zebra über alles! > > Missile Address: 33:48:3.521N 84:23:34.786W > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: changing $0 on solaris?
Hello, I believe that changing $0 is a security breach on some systems. The only UNIX virus/worm that I have seen, set the argv[0] to a null string and the process would not show in the "ps" output list. UNIX ps displays the value of argv[0], and if this string is changed the program can fake being a different process. Cheers, Behdad > -Original Message- > From: Ross Simpson [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, March 27, 2002 6:04 PM > To: Perl Beginners > Subject: changing $0 on solaris? > > > I'm trying to change the value of $0 in a perl script (so > that it shows as > something I define in ps). > Directly modifying $0 works in linux, but on solaris it has no effect. > > Is there another way to do this, or does solaris not allow it? > > thanks > Ross > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: using search backreferences in a variable
On Mar 28, Bryan R Harris said: >Why does this segment not work properly? You would know if you had warnings turned on. perl -we '$match = "cat(\d+)"' yields the warning Unrecognized escape \d passed through at -e line 1. >$match = "cat(\d+)"; >$replace = "\1dog"; >$_ = "cat15"; >s/$match/$replace/g; >print $_; # prints --> \1dog Nope, that prints cat15. Why? Because "cat(\d+)" is the same as "cat(d+)" because "\d" becomes "d". If you had used single quotes, you would have been ok. And $replace the string "_dog", where that _ represents an unprintable character -- specifically, character 1 (SOH). If you had done: $match = 'cat(\d+)'; $replace = '\1dog'; $_ = "cat15"; s/$match/$replace/; print; You would get CLOSER, but not entirely there. $match would be correct, but you would get \1dog instead of 15dog. To fix that requires a bit of work. Here are two solutions: $match = 'cat(\d+)'; $replace = '$1dog'; # XXX: you should not use \1 on the right-hand # side of a regex; you should use $1 $_ = "cat15"; s/$match/qq(qq($replace))/ee; # qq() is just a fancy "..." print; What does THAT do? Well, first, each /e modifier means "execute the right-hand side as code". Since there are two /e's, we'll be executing it TWICE. The first time, qq(qq($replace)) returns the text qq($1dog). When we execute that, we get "15dog". The other way might be easier to understand: $match = 'cat(\d+)'; $replace = sub { "$1dog" }; $_ = "cat15"; s/$match/$replace->()/e; print; This uses a function reference stored in $replace. What this does is delay the evaluation of $1 until it's needed. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** what does y/// stand for? why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
beginners@perl.org
On Thu, 2002-03-28 at 10:50, Nikola Janceski wrote: > There in lies your problem.. you are not passing to the subroutine > correctly. > > try declaring your sub like so: > sub extract_data (\@\@\@){ > but if you do this don't call extract_data with & > use > extract_data(@datum, @seminare, @staedte); > > or pass the ref of the arrays: > extract_data(\@datum, \@seminare, \@staedte); Passing as refs appears to be the preferred method. Subroutine prototypes are flaky and don't work properly with OO based Perl (prototypes can only handle stuff at compile time, while OO method calls happen at runtime). > > > > -Original Message- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED]] > > Sent: Thursday, March 28, 2002 10:39 AM > > To: Chas Owens > > Cc: [EMAIL PROTECTED] > > Subject: Re: && > > > > > > Hi Chas, > > > > > > thanks for your reply. > > The code was the simplified code of a subroutine (below). The Data > > originates from a Webformula and is passed on to the Subroutine like > > > > snippet > > &extract_data(@datum, @seminare, @staedte); > > .. > > .. > > .. > > > > sub extract_data { > > my $dates = shift; > > my $themes = shift; > > my $cities = shift; > > my @dates = split /\s+/, "$dates"; > > my @themes = split /\s+/, "$themes"; > > my @cities = split /\s+/, "$cities"; > > if(@dates && !@themes && !@cities) { > > my $date_count = @dates; > > if($date_count > 1) { > > $sth_between = $dbh->prepare( qq{SELECT * FROM termine > > WHERE beginn BETWEEN ? and ?}); > > $sth_between->execute($dates[0],$dates[1]); > > my $result = $sth_between->fetchrow_hashref(); > > if($result){ > > print $form->p("$result->{beginn}"); > > #print out rest of fields > > } > > } > > else { > > $sth_exact = $dbh->prepare(qq {SELECT * FROM > > termine WHERE > > beginn < ? ORDER BY beginn ASC}); > > $sth_exact->execute($dates[0]); > > my $result = $sth_exact->fetchrow_hashref(); > > if($result){ > > while($result){ > > print $form->p("$result->{beginn}"); > > #print out rest of fields > > } > > } > > else{ > > print $form->p("Tut mir leid nichts gefunden"); > > } > > } > > } > > #here should be all the other if else loop seven in total > > each printing > > #out search results depending on which array or which combination of > > #arrays contains data > > > > > > } > > Marcus > > > > > > > > -- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > The views and opinions expressed in this email message are the sender's > own, and do not necessarily represent the views and opinions of Summit > Systems Inc. > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- Today is Boomtime the 14th day of Discord in the YOLD 3168 Umlaut Zebra über alles! Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Trailing nasty files and sockets closing
People, I am working in a script I would call file2port. The idea is to trail (like tail -f) a file and send it to a TCP port. For every TCP connection incoming to my server, I would trail a file and print its new lines to the client peer. However, I am having two problems I would like to present: 1. I can't tell exactly when the client disconnected. I expected to check for any variable that could tell me the status of that connection but I could not find it. So I am using a "Broken Pipe" signal to discover this, but it is not quite elegant. Question: how can I tell the client has disconnected? 2. I am trailing a file (e.g. myTime). The trailing would be ok if the file is not periodically overwritten by another application. I mean, from time to time, another program cleans the file (the size goes to zero bytes) and starts writing on it again. It seems that perl looses the tracking of it and it takes to much time (and to many lines lost) to re-synch with the file again. Question: How do I improve the trailing so that I wont miss lines when the file is rewritten? I have copied the code in this e-mail, since it's quite small. Regards, Bruno Figueira --- CodeFollows --- #!/opt/MagellanContrib/bin/perl -w use Socket; use IO::Socket; $SIG{CHLD} = 'IGNORE'; $sock = new IO::Socket::INET (LocalHost => 'localhost', LocalPort => 1200, Proto => 'tcp', Listen => 5, Reuse => 1 ); die "Socket could not be created. Reason: $!" unless $sock; while ($new_sock = $sock->accept()) { $new_sock->autoflush(1); $pid = fork(); die "Cannot fork: $!" unless defined($pid); if ($pid == 0) { $thisHost = $new_sock->peerhost(); $thisPort = $new_sock->peerport(); print "New connection from ", $thisHost, ", port ", $thisPort, "\n\n"; $SIG{PIPE} = 'IGNORE'; open(HORAS, "< myTime") or die "Couldn't open myTime for reading: $!\n"; while () { } for (;;) { seek(HORAS, 0, 1); $status = print $new_sock ; if ( !$status ) { last; } sleep 1; } print "Connection Finished! ", "Host: ", $thisHost, ", port ", $thisPort, "\n\n"; close (HORAS); exit(0); # Child process exits when it is done. } # else this is the parent process, which goes back to accept() } close ($sock); An easy way to create the myTime file - #!/bin/csh while ( 1 == 1 ) echo `date` >> myTime sleep 5 end reset it mannualy! - -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: using search backreferences in a variable
\1 is obsolete. try $1 and you also have use the /ee and fix your $replace for the /ee read perldoc perlre $match = qr/cat(\d+)/; $replace = '$1. "dog"'; $_ = "cat15"; s/$match/$replace/gee; print $_, "\n"; # prints --> 15dog > -Original Message- > From: Bryan R Harris [mailto:[EMAIL PROTECTED]] > Sent: Thursday, March 28, 2002 10:46 AM > To: Beginners Perl Mailing List > Subject: using search backreferences in a variable > > > > Why does this segment not work properly? > > $match = "cat(\d+)"; > $replace = "\1dog"; > $_ = "cat15"; > s/$match/$replace/g; > print $_; # prints --> \1dog > > Any ideas? > > TIA. > > - B > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
beginners@perl.org
Yes, prototypes _can_ be used here, but prototypes in general have fallen out of favor amongst the more august members of the Perl community because of the reasons I stated below. Merlin, if you are reading, can you give us your opinion of prototypes? On Thu, 2002-03-28 at 11:11, Nikola Janceski wrote: > good info.. but this doesn't look like a method call. > > I prefer prototypes for modules that I write for internal use at my company, > especially when I don't feel like explaining to 60 people everytime why > thier code doesn't work, when they forget to pass an extra argument. > > > -Original Message- > > From: Chas Owens [mailto:[EMAIL PROTECTED]] > > Sent: Thursday, March 28, 2002 11:03 AM > > To: [EMAIL PROTECTED] > > Subject: RE: && > > > > > > On Thu, 2002-03-28 at 10:50, Nikola Janceski wrote: > > > There in lies your problem.. you are not passing to the subroutine > > > correctly. > > > > > > try declaring your sub like so: > > > sub extract_data (\@\@\@){ > > > but if you do this don't call extract_data with & > > > use > > > extract_data(@datum, @seminare, @staedte); > > > > > > or pass the ref of the arrays: > > > extract_data(\@datum, \@seminare, \@staedte); > > > > Passing as refs appears to be the preferred method. Subroutine > > prototypes are flaky and don't work properly with OO based Perl > > (prototypes can only handle stuff at compile time, while OO > > method calls > > happen at runtime). > > > > > > > > > > > > -Original Message- > > > > From: [EMAIL PROTECTED] > > > > [mailto:[EMAIL PROTECTED]] > > > > Sent: Thursday, March 28, 2002 10:39 AM > > > > To: Chas Owens > > > > Cc: [EMAIL PROTECTED] > > > > Subject: Re: && > > > > > > > > > > > > Hi Chas, > > > > > > > > > > > > thanks for your reply. > > > > The code was the simplified code of a subroutine (below). > > The Data > > > > originates from a Webformula and is passed on to the > > Subroutine like > > > > > > > > snippet > > > > &extract_data(@datum, @seminare, @staedte); > > > > .. > > > > .. > > > > .. > > > > > > > > sub extract_data { > > > > my $dates = shift; > > > > my $themes = shift; > > > > my $cities = shift; > > > > my @dates = split /\s+/, "$dates"; > > > > my @themes = split /\s+/, "$themes"; > > > > my @cities = split /\s+/, "$cities"; > > > > if(@dates && !@themes && !@cities) { > > > > my $date_count = @dates; > > > > if($date_count > 1) { > > > > $sth_between = $dbh->prepare( qq{SELECT * > > FROM termine > > > > WHERE beginn BETWEEN ? and ?}); > > > > $sth_between->execute($dates[0],$dates[1]); > > > > my $result = $sth_between->fetchrow_hashref(); > > > > if($result){ > > > > print $form->p("$result->{beginn}"); > > > > #print out rest of fields > > > > } > > > > } > > > > else { > > > > $sth_exact = $dbh->prepare(qq {SELECT * FROM > > > > termine WHERE > > > > beginn < ? ORDER BY beginn ASC}); > > > > $sth_exact->execute($dates[0]); > > > > my $result = $sth_exact->fetchrow_hashref(); > > > > if($result){ > > > > while($result){ > > > > print $form->p("$result->{beginn}"); > > > > #print out rest of fields > > > > } > > > > } > > > > else{ > > > > print $form->p("Tut mir leid nichts > > gefunden"); > > > > } > > > > } > > > > } > > > > #here should be all the other if else loop seven in total > > > > each printing > > > > #out search results depending on which array or which > > combination of > > > > #arrays contains data > > > > > > > > > > > > } > > > > Marcus > > > > > > > > > > > > > > > > -- > > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > > > -- > > -- > > > > > > The views and opinions expressed in this email message are > > the sender's > > > own, and do not necessarily represent the views and > > opinions of Summit > > > Systems Inc. > > > > > > > > > -- > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > -- > > Today is Boomtime the 14th day of Discord in the YOLD 3168 > > Umlaut Zebra über alles! > > > > Missile Address: 33:48:3.521N 84:23:34.786W > > > > > > -- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > The views and opinions expressed in this email message are the sender's > own, and do not necessarily represent the views and opinions of Summit > Systems Inc. > > -- Today is B
RE: using search backreferences in a variable
> Why does this segment not work properly? > > $match = "cat(\d+)"; > $replace = "\1dog"; > $_ = "cat15"; > s/$match/$replace/g; > print $_; # prints --> \1dog > > Any ideas? Try replacing the "\1dog" with '${1}dog' in the line where you define $replace. That should solve your problem. -dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
beginners@perl.org
There in lies your problem.. you are not passing to the subroutine correctly. try declaring your sub like so: sub extract_data (\@\@\@){ but if you do this don't call extract_data with & use extract_data(@datum, @seminare, @staedte); or pass the ref of the arrays: extract_data(\@datum, \@seminare, \@staedte); > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED]] > Sent: Thursday, March 28, 2002 10:39 AM > To: Chas Owens > Cc: [EMAIL PROTECTED] > Subject: Re: && > > > Hi Chas, > > > thanks for your reply. > The code was the simplified code of a subroutine (below). The Data > originates from a Webformula and is passed on to the Subroutine like > > snippet > &extract_data(@datum, @seminare, @staedte); > .. > .. > .. > > sub extract_data { > my $dates = shift; > my $themes = shift; > my $cities = shift; > my @dates = split /\s+/, "$dates"; > my @themes = split /\s+/, "$themes"; > my @cities = split /\s+/, "$cities"; > if(@dates && !@themes && !@cities) { > my $date_count = @dates; > if($date_count > 1) { > $sth_between = $dbh->prepare( qq{SELECT * FROM termine > WHERE beginn BETWEEN ? and ?}); > $sth_between->execute($dates[0],$dates[1]); > my $result = $sth_between->fetchrow_hashref(); > if($result){ > print $form->p("$result->{beginn}"); > #print out rest of fields > } > } > else { > $sth_exact = $dbh->prepare(qq {SELECT * FROM > termine WHERE > beginn < ? ORDER BY beginn ASC}); > $sth_exact->execute($dates[0]); > my $result = $sth_exact->fetchrow_hashref(); > if($result){ > while($result){ > print $form->p("$result->{beginn}"); > #print out rest of fields > } > } > else{ > print $form->p("Tut mir leid nichts gefunden"); > } > } > } > #here should be all the other if else loop seven in total > each printing > #out search results depending on which array or which combination of > #arrays contains data > > > } > Marcus > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
beginners@perl.org
Hi Chas, thanks for your reply. The code was the simplified code of a subroutine (below). The Data originates from a Webformula and is passed on to the Subroutine like snippet &extract_data(@datum, @seminare, @staedte); .. .. .. sub extract_data { my $dates = shift; my $themes = shift; my $cities = shift; my @dates = split /\s+/, "$dates"; my @themes = split /\s+/, "$themes"; my @cities = split /\s+/, "$cities"; if(@dates && !@themes && !@cities) { my $date_count = @dates; if($date_count > 1) { $sth_between = $dbh->prepare( qq{SELECT * FROM termine WHERE beginn BETWEEN ? and ?}); $sth_between->execute($dates[0],$dates[1]); my $result = $sth_between->fetchrow_hashref(); if($result){ print $form->p("$result->{beginn}"); #print out rest of fields } } else { $sth_exact = $dbh->prepare(qq {SELECT * FROM termine WHERE beginn < ? ORDER BY beginn ASC}); $sth_exact->execute($dates[0]); my $result = $sth_exact->fetchrow_hashref(); if($result){ while($result){ print $form->p("$result->{beginn}"); #print out rest of fields } } else{ print $form->p("Tut mir leid nichts gefunden"); } } } #here should be all the other if else loop seven in total each printing #out search results depending on which array or which combination of #arrays contains data } Marcus -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: changing $0 on solaris?
I do not think your assertion is correct. You see $0 is the name of the parent program, and $1 ..$9 the name of the arguments to $0. You can modify the arguments ($1 .. $9) but not $0. The only way you can modify $0 is to start a new program. If you could include a copy of your program, that will help. __ William Ampeh (x3939) Federal Reserve Board -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
beginners@perl.org
On Thu, 2002-03-28 at 09:44, [EMAIL PROTECTED] wrote: > Hi all, > > > I have some arrays and like to trigger some events depending on which > array or combination of arrays contains data. What I tried was > something like: > snippet > > > if(@dates && !@themes && !@cities) { > > > #do something with the data in @dates > > > } > elsif(!@dates && @themes && !@cities) { > #do somthing with @themes > } > ... > Alas! I doesn't work. Using "and" instead of "&&" doesn't help either. > Or do I have to use "&" instead. Although it doesn't work either. > instead > > Can someone help?? > Thanks > > > > Marcus Willemsen > Online Redaktion > Juve Verlag > Agrippastr. 10 > 50676 Köln > > > tel: ++49(0)221 91 38 80 16 > fax: ++49(0)221 91 38 80 18 > www.juve.de > [EMAIL PROTECTED] > [EMAIL PROTECTED] What do you mean by "doesn't work"? I wrote this sample code and got the following output: #!/usr/bin/perl -w use strict; my @dates = (1); my @themes; my @cities; do_something(\@dates, \@themes, \@cities); @themes = (shift @dates); do_something(\@dates, \@themes, \@cities); shift @themes; do_something(\@dates, \@themes, \@cities); sub do_something { my @dates = @{$_[0]}; my @themes = @{$_[1]}; my @cities = @{$_[2]}; if(@dates && !@themes && !@cities) { #do something with the data in @dates print "do something with the data in \@dates\n"; } elsif(!@dates && @themes && !@cities) { print "do something with the data in \@themes\n"; } else { print "do nothing\n"; } } do something with the data in @dates do something with the data in @themes do nothing Which is exactly what I would expect. Perhaps you could post the original code you had problems with? -- Today is Boomtime the 14th day of Discord in the YOLD 3168 Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
beginners@perl.org
&& and 'and' have different precendence that's the only difference, but in your case it doesn't matter. what exactly are you trying to do? Your code reads if @dates has data and the other two BOTH do not have data then do somthing with @dates else if the above is false and @dates has no data and @themes does have data AND @cities doesn't have data then do something with themes. > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED]] > Sent: Thursday, March 28, 2002 9:45 AM > To: [EMAIL PROTECTED] > Subject: && > > > Hi all, > > > I have some arrays and like to trigger some events depending on which > array or combination of arrays contains data. What I tried was > something like: > snippet > > > if(@dates && !@themes && !@cities) { > > > #do something with the data in @dates > > > } > elsif(!@dates && @themes && !@cities) { > #do somthing with @themes > } > ... > Alas! I doesn't work. Using "and" instead of "&&" doesn't help either. > Or do I have to use "&" instead. Although it doesn't work either. > instead > > Can someone help?? > Thanks > > > > Marcus Willemsen > Online Redaktion > Juve Verlag > Agrippastr. 10 > 50676 Köln > > > tel: ++49(0)221 91 38 80 16 > fax: ++49(0)221 91 38 80 18 > www.juve.de > [EMAIL PROTECTED] > [EMAIL PROTECTED] > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
beginners@perl.org
Hi all, I have some arrays and like to trigger some events depending on which array or combination of arrays contains data. What I tried was something like: snippet if(@dates && !@themes && !@cities) { #do something with the data in @dates } elsif(!@dates && @themes && !@cities) { #do somthing with @themes } ... Alas! I doesn't work. Using "and" instead of "&&" doesn't help either. Or do I have to use "&" instead. Although it doesn't work either. instead Can someone help?? Thanks Marcus Willemsen Online Redaktion Juve Verlag Agrippastr. 10 50676 Köln tel: ++49(0)221 91 38 80 16 fax: ++49(0)221 91 38 80 18 www.juve.de [EMAIL PROTECTED] [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Batch creation of thumbnails
Thank you very much for this script. I dropped in straight onto my box and ran it beautifully. However, I've got a couple of questions about the code. On Wednesday 27 March 2002 6:46 pm, Randal L. Schwartz wrote: > #!/usr/bin/perl > use strict; > > use Image::Magick; > > my $im = Image::Magick->new; > > umask 0022; > > my @names = @ARGV ? @ARGV : grep { -f and -B } <*>; I read this to say, if filenames passed use them otherwise do the whole of the current directory. I believe that the grep takes the list provided by <*> performs the -f and -B filters on the list and assigns the result to @names. Am I correct, and what does the -f and -B do? > > for (@names) { > if (/ /) { > my $old = $_; > tr, ,_,s; > $_ .= ".jpg" unless /\.jpg$/; > ! -e and rename $old, $_ or next; > warn "renaming $old to $_\n"; > } I see the above renames any file containing spaces to include '_' instead > next if /\.thumb\.jpg$/; > my $thumb = "$_.thumb.jpg"; > next if -e $thumb; skip to next if this is a thumbnail, or if the thumbnail already exists > undef @$im; This one confused me. I'm assuming that it's resetting the variables used by the object $im, while keeping the object intact. If this is correct, is this something specific to Image::Magick, or can a similar method work with most objects? > my $ret; > $ret = $im->Read($_) > and warn($ret), next; > $ret = $im->Scale(geometry => '100x100') > and warn($ret), next; > $ret = $im->Write($thumb) > and warn($ret), next; I can see what you're getting at here, but I want to make sure I understand the mechanic. If $im->Read fails, it assigns an error value to $ret, which in turn returns true. Only if the assignment is true, will the second half of the 'and' execute giving the warning and skipping > warn "thumbnail made for $_\n"; > } > > This creates a thumb that is proportional, but at most 100pxl in > either dimension. ImageMagick does all the math. :) Once again, thanks for the help -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Testing for filehandles
> -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, March 27, 2002 6:16 PM > To: Beginners Perl Mailing List > Subject: RE: Testing for filehandles > > > On Wed, 27 Mar 2002, Bob Showalter wrote: > > You can pass a filehandle glob to IO::Handle::opened(): > > Thanks, Bob! After reading the IO::Handle man page, I decided > to distill > this approach a bit further: > > print F if fileno(F); Of course, that's even simpler! Just to be nitpicky, the test maybe should be defined(fileno(F)) Since 0 is a valid file number (STDIN). If you're just going to do the test on the print statement, it's not accomplishing all that much, since the print() will silently fail if the file isn't open. But a test like this would be useful if you want to avoid doing a lengthy operation to generate the data to be printed. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
unallowed characters
Where in the Camel or other resource is the list of characters that we don't want people to type in. I'm still collecting all the resources I lost from my logic board dying. Thanks in advance. -- --- - Teresa Raymond - - Mariposa Net - - http://www.mariposanet.com - --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Quieting 'Name "main::foo" only used once..."
On Wed, 2002-03-27 at 18:46, [EMAIL PROTECTED] wrote: > Hello, All: > > Is there a simple way to stop perl from complaining that a variable is > only used once (possible typo at...)? e.g., > > #! /usr/bin/perl -w > use Getopts::Std; > > getopts('d'); > > print "foo" if ($opt_d); > > If I use 'my()' perl complains that the variable is used in a void > context. Since I'm testing for truth, I suppose that I could set $opt_d to > zero before calling getopts('d')... > > -- > Eric P. > Los Gatos, CA rewrite the code snippet as #! /usr/bin/perl -w use vars '$opt_d'; #tell -w not to be concerned by $opt_d use Getopts::Std; getopts('d'); print "foo" if ($opt_d); or better yet as #! /usr/bin/perl -w use vars '$opt_d'; #tell -w not to be concerned by $opt_d use strict;#keep me from doing something stupid use Getopts::Std; getopts('d'); print "foo" if ($opt_d); -- Today is Boomtime the 14th day of Discord in the YOLD 3168 Keep the Lasagna flying! Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to thread in Perl?
On Wed, 2002-03-27 at 20:40, Ahmed Moustafa wrote: > Chas Owens wrote: > > I wrote some experimental code and it looks like you don't have to reap > > the children (maybe this is just a C thing). > > So, is it OK to fork processes without using waitpid? > > In general, how are the servers (from the fork perspective - > multithreading handling -) implemented in Perl? > If you "fork" without ever waiting on your children, you will accumulate zombies. On some systems, you can avoid this by setting "$SIG{CHLD}" to ""IGNORE"". See also the perlipc manpage for more examples of forking and reaping moribund children. Given the above statement I would first try and see if setting $SIG{CHLD} to 'IGNORE' keeps anything bad from happening. Barring that I would keep a list of all forked children and wait on them during idle time. Another possible solution would be to use the POE modules. I have tried to use the once for a Gtk/Gnome based application that I wanted to be multi-threaded, but ran into errors with the Gnome module (and subsequently found a different way to get around the problem I wanted multi-threading for). I know there was someone on this list with much more experience with POE than I; maybe he will speak up. -- Today is Boomtime the 14th day of Discord in the YOLD 3168 You are what you see. Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: random word from array
"James Taylor" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Hrm, try this: > > @tea = "Meba", "Shaun", "Mark", "Jason", "Rick", "Dan"; > srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`); > print "$tea[rand(5)]\n"; Wow - I would love to say I understand this - but will have to do some more learning first...lol thanks anyway Wytch -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: random word from array
"John W. Krahn" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Wytch wrote: <<>> > If you had warnings enabled Perl would have caught this for tou. But I would have been none the wiser still! You have to understand that I only started Perl two nights ago and have no previous programming experience [apart from html which is not in the same league] - so most of this is greek to me! Though I will enable warnings so I can learn what they mean I will still have to ask the silliest of questions until my brain catches up! > my @tea = qw/Meba Shaun Mark Jason Rick Dan/; tried the qw and it worked! =O) thanks Wytch -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: random word from array
"Randal L. Schwartz" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > That's correct, but if you have a very very very old Perl, you'll need > to add "srand;" at the beginning of your program. Do it just once, > though. That was one of the first things I tried - but I think my Perl is pretty up to date [I only downloaded it the day before yesterdaylol] anyhoo - it didn't make any difference. > The normal idiom is: > > my $one_of_many = $many[rand @many]; I keep seeing this "my $var" hmmm I understand what it is but not really when to use it and when not - *decides to go do some reading up on *my* and experiment* Wytch -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: random word from array
> The problem is not the rand(). The problem was the user didn't put > parentheses around the elements of the array assignment. > > @array = ("This", "That", "Those"); > print $array[rand @array]; Ah ha! those curly brackets have a lot to answer for lol! I can't believe it was something so simple... thanks Wytch -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: random word from array
"Timothy Johnson" <[EMAIL PROTECTED]> wrote in message C0FD5BECE2F0C84EAA97D7300A500D50025811D3@SMILEY">news:C0FD5BECE2F0C84EAA97D7300A500D50025811D3@SMILEY... > > The return value of rand() is a random number between 0 and the optional > argument (1 by default). > > In this case there are 6 elements in the array, so we want a number between > 0 and 5. So try this variation on your code: > > > @tea = ("Meba", "Shaun", "Mark", "Jason", "Rick", "Dan"); > > $get = int(rand(6)); that worked - and does seem to be completely random. I worked this into my existing script and it does the job. thankyou. now I want to build upon it - give it some bells and whistles *muhaha* I am becoming a monster...lol Wytch -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: what does this syntax error mean?
"Jeff 'Japhy' Pinyan" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > On Mar 27, Wytch said: > > >Transliteration replacement not terminated at dot.pl line 18. > > > >What is a Transliteration replacement? > > First, you've shown us NO code, so we can't help correct your code. Actually I didn't want help correcting my code since I already corrected it and got it to work at that point - I had the error come up a few times in totally different snippets of code [and I am sure you all don't want me running to you with every little error lol]. I just wanted to know, in plain english, what a transliteration replacement means rather than the specific coding problem. > Second, you should check the error documentation: > > % perldoc perldiag > > and look for "Transliteration": > > Transliteration replacement not terminated > (F) The lexer couldn't find the final delimiter of a > tr/// or tr[][] construct. > > So it sounds like you've used the tr/// operator and failed to close it > properly. Thankyou =O) Wytch -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: compare char
Steven Massey wrote: > > does anyone know how to compare text > ie > > if ( d < e ) then do this if ( 'd' lt 'e' ) > or > if ( z > h ) do this if ( 'z' gt 'h' ) See the perlop document for more information. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Updating multiple frames in one CGI processing cycle
Ted You could either send a new frameset page, which will load both new frames you require, or you'll have to use a client side scripting language (i.e. javascript) Here's a link that shows one way to do it: http://javascript.internet.com/navigation/change-2-frames.html Carl -- >From: "Ted Markowitz" <[EMAIL PROTECTED]> >To: <[EMAIL PROTECTED]> >Subject: Updating multiple frames in one CGI processing cycle >Date: Wed, Mar 27, 2002, 8:04 pm > > >BlankAs I understand it, because of the single-request/single-response nature >of the HTTP protocol and the way frames are treated as individual, separate >pages, that there's no way to get results from a form in one frame, process it >with a CGI script and the output a new page to both that frame AND another >frame during the same processing cycle? Is that so? In other words, what I'd >like to do is be able to change a navigation bar in one frame and also update >the "main" frame with a new page at the same time. > >An example: when logging in, I'd like to show a simple navbar in the left frame >with just "Login" and "Help". Then based on successfully authenticating in the >main frame using a form for username and password, I'd like to display a new >page in that same main frame AND update the navbar in the left frame to add new >command buttons available only to a logged-in user. > >Any suggestions or pointers to examples would be much appreciated. I've started >to look at doing this via tables without frames, but using frames seems like it >would be much cleaner in principle. > >Thanks. > >--ted -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
compare char
does anyone know how to compare text ie if ( d < e ) then do this or if ( z > h ) do this thanks -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]