Re: appending unique entries to a text file in perl

2001-05-04 Thread Jeff Pinyan
On May 4, Jason Cruces said: >1. Open two files, one to be read from (call it file1) >and another to be written to (file2) Ok, you've got this down fine. >2. Both files will contain a list of entries (some >will be duplicates). If file1 contains an entry that >is not in file2, append it to file

Re: Counting lines on a file

2001-05-04 Thread Jeff Pinyan
On May 4, Susan Richter said: >Can someone tell me what command I can use to go to machines and count the >lines on a certain file? I have log files for every machines (20 all >together). Each log file has lines that would equate to the files that it >found. I need to know how many files ar

Re: Counting lines on a file

2001-05-04 Thread Jeff Pinyan
On May 4, Brett W. McCoy said: >On Fri, 4 May 2001, Susan Richter wrote: > >> Can someone tell me what command I can use to go to machines and count the >> lines on a certain file? I have log files for every machines (20 all >> together). Each log file has lines that would equate to the files t

Re: Counting lines on a file

2001-05-05 Thread Jeff Pinyan
On May 5, Jos I Boumans said: >open(I,"$ARGV[0]"); >my @foo = ; >print scalar @foo; It is considered a dubious practice to read a file into an array; this can use of lots of memory. It is particularly wasteful if the goal is just to find out how many lines there are. Another wasteful use is:

Re: generating passwords

2001-05-05 Thread Jeff Pinyan
On May 5, Collin Rogowski said: >rand(123 - 48) + 48: I am glad you used this construct (and even moreso that you explained the mathematics and logic used therein). I have dealt with programmers who used to write simple mIRC scripts, and expect rand(10, 30); to return a number from 10 to 30

Re: nested each(%hash) question

2001-05-05 Thread Jeff Pinyan
On May 5, Jim Conte said: >the ($key, $value) of %one is a span of time. > >I need to compare this span of time over every $key of %two. > >while (($key1, $val1) = each (%one)) { > > while (($key2, $val2) = each (%two)) { > > if (($key2 >= $key1) && ($key2 < $val1)) { >

Re: generating passwords

2001-05-05 Thread Jeff Pinyan
On May 5, Jos I Boumans said: > for (0..int(rand(4) + 4)) { > $_ = int(rand(2)); > if (/0/) { > $string .= $letters[rand(26)]; > } else { > $string .= int(rand(10)); > } > } #for This is a silly use of a regex -- it's rather wasteful. Just use: if (int rand 2) { $string .= int ra

Re: Regex "([^"]*)

2001-05-06 Thread Jeff Pinyan
On May 7, Clinton said: >I'm tring to extract some values delimited by quotes >I can extract the first set using "([^"]*) but not the second set using >"([^"]*),"([^"]*). Could I have a clue please? The problem is that you are not matching the " after the non-quotes. To fix that, match it: $

Re: Regex "([^"]*)

2001-05-06 Thread Jeff Pinyan
On May 6, Jeff Pinyan said: >On May 7, Clinton said: > >>I'm tring to extract some values delimited by quotes >>I can extract the first set using "([^"]*) but not the second set using >>"([^"]*),"([^"]*). Could I have a clue please? &

Re: regexp trouble

2001-05-07 Thread Jeff Pinyan
On May 7, Johan Groth said: >I want to strip a variable of all characters including a token, i.e. >aaa_bbb_ccc_ddd would become bbb_ccc_ddd. As you can see I want to get rid of >aaa_. Does anyone know how to acomplish this in Perl? > >I've tried: >$tmp = "aaa_bbb_ccc_ddd" >$tmp =~ /^\w+_/ >$tmp

Re: regexp trouble

2001-05-07 Thread Jeff Pinyan
>> $tmp =~ s/^([A-Za-z]+_)(.*)/\2/; >> >> I think the problem is that \w matches an underscore also, and the regexp >> is being greedy as well. There's probably an even better way to do it >> (especially if your strings have foreign characters at it), but that was >> what occurred to me off the t

Re: More hash trouble

2001-05-07 Thread Jeff Pinyan
On May 7, Craig Moynes/Markham/IBM said: >Stumped on this problem >my ( %self ); You're creating a hash above... >$self->{DF_SPEC} = { And then populating a hash reference ($self is not %self). >a => '(Mon|Tue|Wed|Thu|Fri|Sat|Sun)', >A => '(Monday|Tuesday|Wednesday

Re: More hash trouble

2001-05-07 Thread Jeff Pinyan
On May 7, Craig Moynes/Markham/IBM said: > interesting ideas. I will definitely use the self-documenting >variable creation method, extra assignments be damned :) > >Would it also be wise to use the qr// ? > >Such as: >my $shortDayName = qr/(Mon|Tue|Wed|Thu|Fri|Sat|Sun)/; > >then for examp

Re: More hash trouble

2001-05-07 Thread Jeff Pinyan
On May 7, Timothy Kimball said: >For a mind-blowing example of this technique of building big regexes >from little ones, see Appendix B of Jeffrey Friedl's book "Mastering >Regular Expressions". And for extra credit, parse the regex on pg 316 >by hand. ;) Heh, that work is made somewhat simpler

Re: UNTIE () ERROR

2001-05-07 Thread Jeff Pinyan
On May 7, Anshu Anshu said: >Can't modify reference constructor in untie at ./keeq.pl line 320, near >"$dbref)" >BEGIN not safe after errors--compilation aborted at ./keeq.pl line 327. You are trying to untie a reference to a hash. Remove the \ in front of the variable. > 316 sub close_db >

Re: regexp?? Reading in multiple lines to search??

2001-05-08 Thread Jeff Pinyan
On May 8, Ga Bu said: >I am fairly new to perl and having problems with >pulling in multiple lines from a file so I can search >those lines and if it has the expression I am looking >for then I want to return to that file and search >again for the same pattern of lines again and then >search agai

Re: what's wrong in systax

2001-05-08 Thread Jeff Pinyan
On May 8, Anshu Anshu said: > 22 while () { >23 if (/$LOCTAG/i) { >24 ($curloc) = /VALUE="([^"]+)"\s*\w*>/i; >25 $location .= "${curloc}::"; >26 } >27 >28 if (/$TYPETAG/i) { >29 ($curtype) = /VALUE="([^"]+)">/i; >30

Re: what's wrong in systax

2001-05-08 Thread Jeff Pinyan
On May 8, John Joseph Trammell said: >On Tue, May 08, 2001 at 05:24:10PM -0400, Anshu Anshu wrote: >> 22 while () { >> 23 if (/$LOCTAG/i) { >> 24 ($curloc) = /VALUE="([^"]+)"\s*\w*>/i; >> 25 $location .= "${curloc}::"; >> 26 } >> 27 >> 28

Re: mv'ing a file from within perl (w/out /bin/mv)

2001-05-09 Thread Jeff Pinyan
On May 9, Shawn said: >I just want an efficient mv subroutine or module which has such a thing, >but none of the File::* things seem to have mv. > >I would rather not shell out 1 times just to, in the vast majority >of cases, move a file from on dir to another in the same fs. If the standard

Re: Very beginner question

2001-05-09 Thread Jeff Pinyan
On May 9, [EMAIL PROTECTED] said: >(name = john) > >if I am trying to just extract "john" for the value $b, why would the >following script not work. I thought it would take bothIt returns the >full (name=john) Let's run your regex through the regex explainer: > (my $b=$_) =~ s/^(\() (\w

RE: RE: Help with Perl (fwd)

2001-05-09 Thread Jeff Pinyan
On May 9, [EMAIL PROTECTED] said: >Somebody please help me uderstand the deal with "qq". I have run tests >on all three lines of code below and it turns out that #1 and #3 work >but #2 does not. I am under the impression that "qq" acts as double >quotes. So why doesn't #2 work isn't it the same a

RE: @INC

2001-05-09 Thread Jeff Pinyan
On May 9, Stephen E. Hargrove said: >-BEGIN PGP SIGNED MESSAGE- >Hash: SHA1 > >On Thu, 10 May 2001, King, Jason wrote: > >> Stephen E. Hargrove writes .. >> >> >how do i add new directories to @INC? i've managed to bungle one of my >> >debian systems, and apt-get relies pretty heavily on

Re: New to Perl

2001-05-10 Thread Jeff Pinyan
On May 10, Soin, Harinder said: >I am new to perl and I am qucikly realizing that a solid understanding of >Regular Expressions is a necessacity. Can anyone point me a good source >where I can go from zero to 100 miles in a short period of time. That sounds dangerous. Regexes are something you

RE: New to Perl

2001-05-10 Thread Jeff Pinyan
On May 10, Crandell, Daniel (TIFPC) said: >Same situation here on this end. Buy oreilly book, "mastering regular >expressions" 34.95 barnes and noble, it has picture of the owl. *THAT* is the reason I am writing my book. J. Friedl is not going to be working on the second edition of that book,

Re: New to Perl

2001-05-10 Thread Jeff Pinyan
On May 10, Peter Scott said: >At 09:29 AM 5/10/2001 -0400, Kevin Meltzer wrote: >>On Thu, May 10, 2001 at 09:17:30AM -0400, Jeff Pinyan ([EMAIL PROTECTED]) >>spew-ed forth: >> > On May 10, Crandell, Daniel (TIFPC) said: >> > >> > >Same situation he

Re: Taint flag

2001-05-10 Thread Jeff Pinyan
On May 10, Peter Cline said: >When attempt to use the taint flag I get the following complaint when >invoking perl from a command line (using -c, -w, and -wc): > >Too late for "-T" option at survey_select.pl line 1. > >The code runs however, and does what is expected. Just curious if anyone >k

Re: beginner here - with basic cgi trouble

2001-05-10 Thread Jeff Pinyan
On May 10, David A. Desrosiers said: > >>It didn't work ... >>the reason .. Attack of the ^M 's > > perl is your friend: > > perl -pi -e 's#\r\n#\n#g' formail.pl Why use s/// if you don't have to? japhy% perl -pi -e 'tr/\r//d' files... Why use Perl if you don't have to?

Re: hex conversion

2001-05-10 Thread Jeff Pinyan
On May 10, Paul Cotter said: >What combination of sprintf/pack/upack/asc/hex/xyz.pm etc will allow me >to convert a string in to a string hex equivalent. I dare say, in Perl's >little quirks there is an arcane subroutine called something like dtcnvx >that does just what I want... Sadly, the oct(

Re: hex conversion

2001-05-10 Thread Jeff Pinyan
On May 10, Paul Cotter said: >print dtcnvx('Ab c') # gives 41622063 Ohh. Oops. $x = unpack 'H*', 'Ab c'; -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/ Perl Programmer

RE: Sorting

2001-05-10 Thread Jeff Pinyan
On May 10, Nic LAWRENCE said: >> > Can anybody suggest the most efficient method to do the following... >> > >> > I have an array of email aliases like the following: >> > [EMAIL PROTECTED]: sys >> > [EMAIL PROTECTED]: coookiecom >> > [EMAIL PROTECTED]:

RE: Sorting

2001-05-10 Thread Jeff Pinyan
On May 10, Jeff Pinyan said: > { >my %cache; >@new = sort { > ($cache{$a}) = $a =~ /\@([^:]+)/ if not exists $cache{$a}; > ($cache{$b}) = $b =~ /\@([^:]+)/ if not exists $cache{$b}; > $cache{$a} cmp $cache{$b} >} @orig; } -- Jeff "

RE: Sorting

2001-05-10 Thread Jeff Pinyan
On May 10, Peter Scott said: >At 05:55 PM 5/10/01 -0400, Jeff Pinyan wrote: >>That sorting method does a lot of work -- that is, it does things more >>than once. I suggest you use a schwarztian transform, or the Orcish >>manuever, to increase speed. > >I'd lik

[OT] Origin of "Orcish Maneuver"

2001-05-11 Thread Jeff Pinyan
On May 11, Paul said: >> That sorting method does a lot of work -- that is, it does things >> more than once. I suggest you use a schwarztian transform, or the >> Orcish maneuver, to increase speed. >> >> { >> my %cache; >> @new = sort { >> ($cache{$a}) = $a =~ /\@([^:]+)/ if no

Re: Regexp Question Again

2001-05-11 Thread Jeff Pinyan
On May 11, Gross, Stephan said: >I wasn't clear last time. I wrote: >>I want to match the following: >>1) the letters "PT" >>2) a space or nothing >>3) a word that may or may not be in parentheses or even not exist >>and return item #3 (which may be null) >>Example: >>PT (XYZ) or PT XYZ or PTXYZ

Re: Help With Matching

2001-05-11 Thread Jeff Pinyan
On May 11, FLAHERTY, JIM-CONT said: >$test1 = s/<>//g ^ This gives an error. s!<>!!g; -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/ Perl Programmer at RiskMetrics Gr

Re: problems with CGI script

2001-05-12 Thread Jeff Pinyan
On May 12, Pam Derks said: >I'm a newbie struggling to total up a web users survey for work. The >HTML form is a separte document, which calls up the cgi script. I've >been reading the CGI module and figured out how to get the key/value >paris. Now, I want to tally the answers, i.e. 10 users cho

Re: Sorting a file

2001-05-13 Thread Jeff Pinyan
On May 13, Thomas Leuxner said: >#mydomain.com >mydomain.com anything >[EMAIL PROTECTED] tlx > >#newdomain.com >newdomain.com anything > > >#somewhere.com >somewhere.com anything > I suggest you make a hash of array reference

Re: Sorting a file

2001-05-13 Thread Jeff Pinyan
On May 13, Jeff Pinyan said: >if (/(?:^|\@)(\S+)/) { I had a precedence error in my code here. That regex will match at the beginning of the line every time. It should be: if (/\@(\S+)/ or /(\S+)/) { # ... } Sigh. And I'm writing a book about these. I should ge

Re: Sorting a file

2001-05-14 Thread Jeff Pinyan
On May 14, Paul Cotter said: >next if /^#?$/; # skip empty lines and comment lines No. I had a bad regex weekend (as Paul could personally attest to). The author asked the same question. next if /^(#|$)/; will work, as well next if /^#/ or /^$/; I'm sorry about the mixup. I had origi

Re: flock

2001-05-14 Thread Jeff Pinyan
On May 14, Brian Shoemaker said: >The Perl 5 book I have says flock function doesn't work in Windows systems. > >I don't want to create a lock file each time someone accesses a file and >then have to delete that lock. A rather clever way to emulate locking is to use mkdir() and rmdir(). Althoug

Re: flock

2001-05-14 Thread Jeff Pinyan
On May 14, Peter Scott said: >Ooh, that is clever. Has it been encapsulated in a CPAN module? No. It can break on NFS. >> 1 until mkdir "$_[0].lck", 0777; > >Perhaps sleep 1 until mkdir would be a little less stressful on the average >system :-) Feh. ;) -- Jeff "japhy" Pinyan [EM

RE: flock

2001-05-14 Thread Jeff Pinyan
On May 15, King, Jason said: >>A rather clever way to emulate locking is to use mkdir() and rmdir(). >> >>Although it requires you to create a lock file, it's atomic and safe. > >are you sure ? .. just because it constitutes one Perl statement doesn't >mean that it's atomic .. I suspect mkdir has

Re: negative matching?

2001-05-14 Thread Jeff Pinyan
On May 14, Noah Sussman said: >I am trying to write a simple script to insert ALT attributes into IMG tags >that don't have them, leaving other IMG tags untouched. > >The problem is that I can't figure out how to tell Perl to search for >strings beginning with "" AND not containing "ALT=" >(and i

RE: Perplexing problem.........probably beginners luck??

2001-05-15 Thread Jeff Pinyan
On May 15, Paul said: > >--- Peter Cornelius <[EMAIL PROTECTED]> wrote: >> The doesn't read into $_. You can add a 'print $_;' in there >> to verify it. I think you're getting confused by the >>while(){...} >> structure. This puts the result of the readline into $_ for you if >> the is t

Re: formatting

2001-05-15 Thread Jeff Pinyan
On May 15, Liger-dc said: >What does the following formatting do? > >$line =~ /^; .ot (\d+)/) I suggest you download YAPE::Regex and YAPE::Regex::Explain from CPAN -- the 'explain' program automatically generates an explanation for a regex: friday:~ $ echo '^; .ot (\d+)' | explain The regular

Re: Sorting a Two Dimensional Array

2001-05-16 Thread Jeff Pinyan
On May 16, Paul said: >"or" also short circuits, and some consider it more readable, but it >(and the "and" operator) always return(s) a boolean value, while || >(and &&) return the value of the first true expression. > > $a or $b # returns 1 if either has a non-false value, else '' > $a || $b

Re: special variables

2001-05-16 Thread Jeff Pinyan
On May 16, Liger-dc said: >are the variables $1 and $2 special variables? and if >so what do they do? Read perldoc perlvar: $ Contains the subpattern from the corresponding set of parentheses in the last pattern matched, not counting patterns matched

Re: Array Question

2001-05-16 Thread Jeff Pinyan
On May 16, jane doe said: >How do I remove duplicate items from an array? I apologize for being a >"newbie". :) Please read 'perldoc -q duplicate' or 'perldoc -q unique'. You can see these answers in Perl FAQ #4, online at http://www.perldoc.org/, or on your computer via the 'perldoc' command.

Re: Variable Creation

2001-05-17 Thread Jeff Pinyan
On May 17, Alberto Manuel Brandao Simoes said: >RULE ---> FILE* > >::t { > for (@FILE) { > #do something > } >} > >The idea is, when parsing the RULE, create the FILE array so that the user can >browse it. This is done by an eval, so I can construct a string initializing

[ADV] Symbol Table (was Re: Variable Creation)

2001-05-17 Thread Jeff Pinyan
On May 17, Paul Johnson said: >You can't. You are trying to use symbolic references and when you have >strict turned on you are promising not to do that. >my $varname = "myvar"; >{ >no strict "refs"; >no strict "vars"; >@$varname = ('a','b','c'); >} It's important to know one thing

Re: Compare statement.

2001-05-17 Thread Jeff Pinyan
On May 17, Doug Johnson said: >my $x = "return"; > >if (($x = "a") || ($x = "test" ) || ($x = "return" ) || ($x = "x-retun")) > { > print("bunch of foo); > } First, that's NOT the code you have. If it IS, it's broken. if ($x eq 'a' or $x eq 'test' or $x eq 'return' or $x eq 'x-retu

Re: String concatenation in ?: structure.

2001-05-17 Thread Jeff Pinyan
On May 17, Peter Cornelius said: >$returnCode eq "o.k." ? $subject .= " -OK-" : $subject .= " -FAILED-"; You're being bitten by precedence. ?: is stronger than .=, so your code is like: ($foo == 1 ? $bar .= "this" : $bar) .= "that"; Which means that if $foo is 1, $bar gets "thisthat" tacked

Re: doubt about $ in perldoc perlvar

2001-05-17 Thread Jeff Pinyan
On May 17, [EMAIL PROTECTED] said: > $ > Contains the subpattern from the corresponding set > of parentheses in the last pattern matched, not > counting patterns matched in nested blocks that have > been exited already. (Mnemonic: like \digits.

RE: help with arrays

2001-05-17 Thread Jeff Pinyan
On May 17, Yacketta,Ronald J said: >backint:maple aspen pine >online:orange palm cherry > >is it possible to read in this file and what ever is before the : would >become the name of >the array? The key is, DON'T DO THAT. Don't make arrays with names you don't know ahead of time. It's best to

Re: Quick rounding to nearest integer

2001-05-18 Thread Jeff Pinyan
On May 18, Craig Moynes/Markham/IBM said: >I looked through my book (perl nutshell) and PP has not arrived yet, so I >will ask here. > >I have an number that needs to be rounded to the nearest whole number. >This is my solution: Timothy Kimball has a good solution, but I have a generalization:

RE: Quick rounding to nearest integer

2001-05-18 Thread Jeff Pinyan
On May 18, John Storms said: >Not the best code, but it works fine. > ># roundup(,[]); ># returns a truncated and rounded up value. >sub roundup { >my($i); for($i=0;$i$char = substr($num,$i,1); >$next = substr($num,$i+1,1); Rounding numbers shouldn't be a

Re: Help - Rookie question on Arrays

2001-05-18 Thread Jeff Pinyan
On May 18, Paul said: > @hits = grep /^$TEST1$/, @HOLDER; Do not use a regular expression to check for equality. It breaks far too often. * the $ anchor does not match the end of the string -- it matches the end of a string OR before a newline at the end of a string * if $TEST1 has any

Re: truncating a string

2001-05-18 Thread Jeff Pinyan
On May 18, David Merrill said: >$title =~ s/\s*$//; > >where $title = "The Linux Programmer's Guide " > >and it is being truncated after the ' mark. All I want to do is remove >the trailing spaces from the string. Can someone please help? You've already solved your problem about single q

Re: copying an array

2001-05-18 Thread Jeff Pinyan
On May 18, Liger-dc said: >I'm currently copying two 1-dimensional arrays using >for loops. Is there an easier way as this may tag my >cpu due to the huge numbers I am using. What's wrong with: @foo = @bar; -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ Are

Re: script review

2001-05-18 Thread Jeff Pinyan
On May 18, Yacketta,Ronald J said: >Do you mind if I post a script I have been hacking away at for a week or >so now? I really would like input to improve its performance etc, I am >using this script as my tutorial. I have learned a great deal from this >list and by hacking away. I think code re

RE: REVIEW: please review the following

2001-05-18 Thread Jeff Pinyan
My review is at: http://www.pobox.com/~japhy/perl/wki.txt I will have a bit of a rewrite demonstrating some of the points raised in my critique at a similar URL in a few minutes. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ Are you a Monk? http://www.perlm

RE: REVIEW: please review the following

2001-05-18 Thread Jeff Pinyan
Here's my "vision" of the new program: http://www.pobox.com/~japhy/perl/wki-new.txt -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/ Perl Programmer at RiskMetrics Group, Inc. http://

RE: REVIEW: please review the following

2001-05-18 Thread Jeff Pinyan
On May 18, Yacketta,Ronald J said: >Is this error version specific? >syntax error at ./wki.pl line 101, near "tr/ //d for " >Execution of ./wki.pl aborted due to compilation errors. ... for LIST; was added in 5.005, so for 5.003, you'll need to do: for (LIST) { ... } -- Jeff "japhy" Pin

RE: passing array values into a command string

2001-05-18 Thread Jeff Pinyan
On May 18, Wagner-David said: >$_ will have the carriage return as part of the name, so should do a chomp >before putting in the hash otherwise would have to have the carriage rturn >as part of the testing process and I don't think you want that. So the line >right after , place a chomp. I beg t

Re: copying an array

2001-05-20 Thread Jeff Pinyan
On May 19, Aaron Craig said: > >sub PassAnEntireArray(@) > { > my(@array) = @_; > ...do some stuff... > } > >sub PassAnArrayRef($) > { > my($ar) = @_; > ... do some stuff... > } > >I assume passing array refs (and hash refs for that

Re: REVIEW: judfr.pl (file indexer/ dup remover)

2001-05-21 Thread Jeff Pinyan
A rather scantily clad review is at http://www.pobox.com/~japhy/perl/judfr.txt There's not much to see, because I'm not really sure I understand the data structure (or rather, its makeup and purpose), but I do have a couple of comments about things I would do differently. -- Jeff "japhy" Pin

Re: mkdir / Security problems !

2001-05-21 Thread Jeff Pinyan
On May 21, Laurent Marzullo said: >Insecure dependency in mkdir while running setuid at >.../File/Path.pm line 137 >sub create_rcsdir >{ > local( $cctrl , $group ) = @_; > local( $rcsdir ) = $ENV{ RCSDIR }; > > mkpath( $rcsdir , 1 , 0750 ); >} I bet the problem is due to

Re: Beginner question

2001-05-22 Thread Jeff Pinyan
On May 22, Mark on GCI Server said: > I'm trying to populate an array from a file, I think I've got the array >populated, however, I'm not sure. I then want to compare an input against >the array to determine if its there, then look at the second component of >each record. Any assistance would

Re: Beginner question

2001-05-22 Thread Jeff Pinyan
On May 22, Mark on GCI Server said: >open(TESTER, "print "Enter a username: "; >$input = ; You need to chomp $input, since it has a newline at the end. >$x = 0; >$y = 0; >$w = 0; >$z = 1; >if ( ne "") { That reads a line (and it is lost forever). >while($line = ) { >c

Re: ternary operator stability(e.g., in "case" statements)

2001-05-22 Thread Jeff Pinyan
On May 22, Paul said: >I know that in many C compilers, the a ? b : c construct with the >ternary ?: operator si not stable after the second or third nesting, >but I've never seen that sort of problem in tests I've run in Perl. The only to watch out for is precendence: $a ? $b = $c : $b = $d;

Re: Passing command line arguements

2001-05-22 Thread Jeff Pinyan
On May 22, Richard Thompson said: >We have moved a website off a server outside our offices to one inside. >everything went fine but one of our cgi is not working so using some >info shared in this forum we tried to run from the command line. now >here is the problem we cannot get it to pass the

Re: copying an array

2001-05-22 Thread Jeff Pinyan
On May 21, Paul Cotter said: >> The problem is: PROTOTYPES MUST BE SEEN BEFORE THE FUNCTION IS CALLED. > >I've seen this statement before and do not really understand it, having come >from a 'true-compiler' background. It is the 'seen' that puzzles me. > >If I have a 'require' then I believe the

Re: Beginner Question

2001-05-22 Thread Jeff Pinyan
On May 22, Peter Cline said: >Try this. >my $text = "Browser/Version Platform"; >my ($keep,$discard) = split / /, $text; >print "$keep\n"; > >This splits on space and saves the part you want to the variable $keep and >the rest to $discard. Actually, it splits on EXACTLY one space. That can cau

Re: Beginner Question

2001-05-22 Thread Jeff Pinyan
On May 22, Peter Cline said: >> @parts = split ' ', "this and that"; >> { local $" = ") ("; print "(@parts)"; } >> # (this) (and) (that) > >Will the ") (" assign any amount of space to the list separator? >This is interesting. I haven't encountered this syntax before. Using split ' ' is

Re: Regular Expressions

2001-05-23 Thread Jeff Pinyan
On May 23, Jos Boumans said: >Or a really one: > >if ($x =~ /\D/) { >print "found non digit, do not pass go, no 20 grands for you"; >} else { >print "good boy"; >} > >where \D stands for NON digits The only problem is that "" passes that regex. For that reason, I would suggest something

Re: Regular Expressions

2001-05-23 Thread Jeff Pinyan
On May 23, Randal L. Schwartz said: >>>>>> "Jeff" == Jeff Pinyan <[EMAIL PROTECTED]> writes: > >Jeff> if (length($x) and $x =~ /\D/) { fail() } > >Simpler... > >if ($x =~ /\d/ and $x !~ /\D/) { winner! } Yeah, I was thinking of t

Re: Regular Expressions

2001-05-23 Thread Jeff Pinyan
On May 23, Kyrytow, Stefan said: >Why they are called Regular Expressions, I am not to sure. They should be >called Frustrating Expressions. You might want to take a look at http://www.pobox.com/~japhy/docs/LPRE.html -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~j

Re: New line in Regular expression.

2001-05-23 Thread Jeff Pinyan
On May 23, pda said: > and come to the new line and also check whether if there is a in >the given file if it finds it has to replace with a other string. > >this is what i tryed on the command prompt. > >perl -pi -e 's{^

Re: New line in Regular expression.

2001-05-23 Thread Jeff Pinyan
On May 23, Timothy Kimball said: >2. Use the "s" modifier to treat the slurped-up file as a single string. The /s modifier changes the meaning of . only, and not ^ or $ -- see my response. See chapter 5 of LPRE: http://www.pobox.com/~japhy/docs/LPRE.html#5.%20more%20pattern%20modifiers --

Re: Regrex question

2001-05-23 Thread Jeff Pinyan
On May 23, David Gilden said: >#!/usr/bin/perl > >$test = "dave David Davy"; > >$i=0; > >### Does not work want to count the number of matches... >$regex= ($test=~ s/(dav)/$i++ $1/eig); > >print "$regex $i\n"; Do you want to count matches, or change the string? If you just want to count th

Re: syntax question

2001-05-23 Thread Jeff Pinyan
On May 23, Peter Cline said: >Does anyone know a better way to say @{$$hash_name{arrayref}}? Doing $$foo{...} or $$foo[...] is often confusing for people to read. That's why the -> operator exists: $foo->{bar} # is like $$foo{bar} $foo->[$i] # is like $$foo[$i] So you could write: @

Re: syntax question

2001-05-23 Thread Jeff Pinyan
On May 23, Paul said: >{ local @ary = $hash_name->{arrayref}; # @ary now the array > print $ary[4]; # access is "normal" >} # aliasing ends with scope Err, I think you mean local *ary = $hash_name->{arrayref}; That will make @ary an

Re: Perl Programming Question

2001-05-23 Thread Jeff Pinyan
On May 23, Tom Yarrish said: >Been reading the list for a little while, and had sort of a philosophy >question for the group. I've been trying to learn Perl for some time >(in fact, my company has offered to pay for me to take a Sun course on >it). In the mean time I've been reading through the

Re: problems using split

2001-05-23 Thread Jeff Pinyan
On May 23, Andy Roden said: >($router_table{i},$router_type{i}) = split(/\|/, >$router_tables{i}); You probably want that to be $i, not i. >if ($router_table{i} ne "") { >print SH "\"$router_table{i}\" "; >} There too. >else { >print SH "\"$rout

RE: Modifying/Deleting lines in a file

2001-05-24 Thread Jeff Pinyan
On May 24, David Blevins said: >So, as far as editing files in a subroutine of a script, there does not seem >to be an easier or more performant way? > >Would it be performant to call the perl command as a subprocess, as in: > >`perl -ni -e 'print unless /I'm a bad line, delete me\./' thefile`;

Re: Unusual Sort question

2001-05-24 Thread Jeff Pinyan
On May 24, Gustho said: >Below is a sample directory listing of the mail folder >on a Linux box, I would like to sort the same using >the last field (ie. lward, ohara, dray) starting with >the 2nd character (ie from ward , hara and ray) : > >-rw--- 1 lward mail0 May 24 15:43 lward >-rw

Re: Unusual Sort question

2001-05-24 Thread Jeff Pinyan
On May 24, Jeff Pinyan said: >Now the GRT looks like: > > @sorted = > ># get rid of leading sorting string >map { s/^\S+\s+// } That should be map { s/^\S+\s+//; $_ } or even grep { s/^\S+\s+// } You can use grep() here since all lines will match tha

Re: File Age

2001-05-25 Thread Jeff Pinyan
On May 25, Keith A. Humphrey said: >Is there a perl command that can tell me the age of a file? Not on Unix. You might be able to get a Windows or Mac specific module to get the creation date of a file on those systems, but Unix does not store the creation date of a file -- you can, however, ge

Re: [CGI] RE: newbie need help

2001-05-26 Thread Jeff Pinyan
On May 26, Manoj Jacob said: >I've done some programming in perl mainly for web oriented stuff >There's one thing i've always wanted to understand...Sometimes the perl >program ends with .pl and sometimes .cgimaybe i'm a very bad programmer >and i'm really dumb that i've not understood th

Re: Regex problem

2001-05-29 Thread Jeff Pinyan
On May 28, Bornaz, Daniel said: >$stt="The food is under the bar in the barn in the river."; >$stt=~/bar(.*?)river/; >print "$&"; > >The output is: >bar in the barn in the river > >Instead of the expected: >barn in the river For the meantime, you might like to look at chapter 6 of "Learning Per

Re: How to delete an element in array?

2001-05-29 Thread Jeff Pinyan
On May 29, Jie Meng said: >I am a newbie. Would you please tell me how to delete an element in an >Array? The delete() function works on arrays (in Perl 5.6), but it doesn't remove the element (unless it occurs at the end of the array). You want to use the splice() function. splice @array, $

Re: How to delete an element in array?

2001-05-29 Thread Jeff Pinyan
On May 29, Walt Mankowski said: >On Tue, May 29, 2001 at 11:59:18AM -0700, Randal L. Schwartz wrote: >> > "Brett" == Brett W McCoy <[EMAIL PROTECTED]> writes: >> >> >> Uh, careful. This got added to 5.6.1 to support pseudo-hashes and is >> >> probably coming back out when pseudo-hashes get

Re: substitution problem

2001-05-29 Thread Jeff Pinyan
On May 29, Me said: >If you will allow perl to make use of temporary files >behind the scenes (which is normally perfectly ok), >Cookbook recipe 7.9 is a whole heck of a lot >simpler. As a command line one liner: > >perl -pie 's/a/p/g' try.txt foo.txt > >will go thru files try.txt and foo.txt

Re: Shelling PERL or is it PERLing Shell

2001-05-29 Thread Jeff Pinyan
On May 29, George Balogi said: >#!D:perl/bin/ -w >cut -f3,5 -d"|" try You appear to be writing shell code in Perl. Perl is not shell, and vice-versa. Furthermore, cut isn't implemented in DOS (to my knowledge). You need to basically write this as Perl code. Here are some helpful hints: *

Re: Cleaning up 'uninitialized value'

2001-05-30 Thread Jeff Pinyan
On May 30, Craig Moynes/Markham/IBM said: >I have a script that when it runs (with no parameters) I have warnings >displayed (we have all seen them but) : > >>Use of uninitialized value at ./log_prune.pl line 14. Because @ARGV is empty, $ARGV[0] is undef. >if ( (-T $ARGV[0]) ) Use: if (@ARG

Re: 'sort(func(list))' <=same as=> 'sort func (list)' ?!?!?

2001-05-30 Thread Jeff Pinyan
On May 30, Mark Salazar said: >I was recently bitten by this, and it's not clear to me (and others) if >this is correct Perl behavior or not. > >If you have a user defined function 'func' that returns a list and you'd >like to sort that return value it's reasonable to try: > > sort(func(@list));

Re: Hash tutorial?

2001-05-30 Thread Jeff Pinyan
On May 30, Paul said: >Just an elaboration -- you can do this: > > @hash{ qw( a b c ) } = qw( 1 2 3 ); > >which should give you the same as: > > %hash = ( a => 1, b => 2, c => 3 ); Only if %hash was previously empty. Assigning to a hash all at once clears it and sets the key-value pairs you p

Re: On Beginners' Mindsets, Part II

2001-05-30 Thread Jeff Pinyan
On May 30, Peter Scott said: >*Curiosity* is an essential trait for the programmer. In all seriousness, >if you don't have a deep desire to find out how things work - in >particular, software - this may not be the field for you. Principally >because our tools are rarely so perfect at encapsu

Re: iinfinite loop

2001-05-30 Thread Jeff Pinyan
On May 30, David Gilden said: >$data = 'some >multi line >string'; > >while($data){ > push(@everyline, $_); >} You're confusing this with while () { # do something with $_; } You can do: @lines = split /\n/, $data; or you can download the IO::String module from

Re: Sleeping for less than a second

2001-05-30 Thread Jeff Pinyan
On May 30, Craig Moynes/Markham/IBM said: >Is there anyway to sleep for less than a second using the default >installation of perl ? friday:~ $ perldoc -q sleep =head1 Found in /usr/local/lib/perl5/5.00502/pod/perlfaq8.pod =head2 How can I sleep() or alarm() for under a second? If you want fin

  1   2   >