[8250] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1866 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 11 21:17:30 1998

Date: Wed, 11 Feb 98 17:00:23 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 11 Feb 1998     Volume: 8 Number: 1866

Today's topics:
    Re: "Mastering Regular Expressions" (Georg Bauer)
    Re: Code Example Needed (Martien Verbruggen)
    Re: Counter problem - resets <John.Adams@BentonvilleAR.ncr.com>
        EXAMPLES: Simple I/O operations <tchrist@mox.perl.com>
    Re: Expanding Filenames? (Martien Verbruggen)
    Re: FAQless Forays (was: Code Example Needed) (Devin L. Ganger)
        Filesystem free space under WinNt <thomas.strohmaier@sap-ag.de>
    Re: Help with code (Martien Verbruggen)
    Re: Help!! pattern matching (Martien Verbruggen)
    Re: How Do You Write an Empty While Statement? <rra@stanford.edu>
    Re: how to properly interpret a '-?' command line optio <tchrist@mox.perl.com>
    Re: How to use Mail in Perl ? /$wl007$/ (William R. Ward)
    Re: Making Submit buttons into Images (Nathan V. Patwardhan)
    Re: Need some help ! (Martien Verbruggen)
    Re: Negative of a minus sign is a plus? <rra@stanford.edu>
    Re: New Perl book reviews (Michael J Gebis)
    Re: Possible bug in "or" operator (Stephen P. Clouse)
    Re: Possible bug in "or" operator (Earl Hood)
        PUZZLE: Answer me these questions three <tchrist@mox.perl.com>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 10 Feb 1998 19:49:00 +0100
From: Georg_Bauer@muensterland.org (Georg Bauer)
Subject: Re: "Mastering Regular Expressions"
Message-Id: <199802101949.a58598@ms3.maus.de>

Patrick Timmins <ptimmins@netserv.unmc.edu> wrote:

> It is the most important book I've
> purchased in the past year or two (or more), and definitely one of the
> best technical books I've ever read.

Hmm. I would add "Advanced Perl Programming" by Sriram Srinivasan - it
definetely was one of the best Perl-related books _I_ read in the last
year. It is one of those rare books that not only gives details and
solutions, but has a very fluid style, so it is just fun to read. And
the techniques in the book are really interesting.

bye, Georg


------------------------------

Date: 11 Feb 1998 23:08:15 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Code Example Needed
Message-Id: <6btb0v$46k$1@comdyn.comdyn.com.au>

In article <34e1b633.217265825@news.mw.mediaone.net>,
	mystra@torilmud.com (Eileen Kortright) writes:
> On 11 Feb 1998 15:16:49 +0100, Calle Dybedahl
> <qdtcall@esb.ericsson.se> wrote:
> 
>>But you obviously missed the recurrent posting about chosing a
>>relevant subject line.
> 
> Well, obviously I did, since it wasn't included in the messages I

You read 217 messages and not one of those contained something like:

Please read the following information on how to choose a good subject
line:

http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post

> is wrong with my subject line? I want a code example, that's what my
> subject was. How is that irrelevant?

You will realise, if you read the above article, why your subject line
could have been better.

> Listen, if all you are going to do is nitpick and slam my post, don't
> reply, okay? My gosh you people can be rude.

Ok, there have been some threads about this lately. Yes, some replies
are rude. However, replies that explain to people how to get a better
response to their posts should not be considered rude. Posts that
explain to people how to read the documentation, and where to find
modules, are not rude.

I could go into this whole matter again, but it's been done.  I assure
you: most of these posts are not intended to be rude, but to educate.
Next time there is a problem, the poster who has taken one of these
replies to heart will know where to look first. If they then can't
find the answer, they'll know how to post a message that is most
likely to get a speedy, correct response.

If you spend a few months on this newsgroup, weeding through most, if
not all, of the messages, you will start to understand why it is like
that. The volume on this group is just too large.

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | Begin at the beginning and go on till
Commercial Dynamics Pty. Ltd.       | you come to the end; then stop.
NSW, Australia                      | 


------------------------------

Date: Wed, 11 Feb 1998 18:32:39 -0600
From: John Adams <John.Adams@BentonvilleAR.ncr.com>
Subject: Re: Counter problem - resets
Message-Id: <34E24326.1BDB@BentonvilleAR.ncr.com>

Tom Christiansen wrote:

> I increasingly begin to understand why some universities require
> that its compsci majors study the Euclid's Prime Number Theorem,
> the Fundamental Theorem of Calculus, Cantor's Diagonalization Proof,
> Goedel's Incompleteness Theorem, and the ramifications of Halting Problem
> in everyday life.  These may not be involved in daily programming, but
> it helps develop a rigorous mind.

Gee, I thought the reason I could hack away at problems and get decent,
workable solutions was because I was an ex-English major, actually. But,
now that I think about it, I think those advanced math courses did
almost as much good as the seminar on the Beat Generation. Maybe more.

	John "skipped all the grammar courses, though" A

P.S. For the humor-impared, I actually _am_ an ex-English major, I
actually am _not_ being sarcastic above, I actually did take that
seminar, in which one of the students turned in a program simulating
William Burrough's cut-up method, and I'm actually just killing time
till I'm done with this reload--damn! It just rejected the tape again.
Back to work.


------------------------------

Date: 12 Feb 1998 00:07:51 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: EXAMPLES: Simple I/O operations
Message-Id: <6btegn$2c4$13@csnews.cs.colorado.edu>

The following set of examples has been used by me and my trainers in
some of our Perl training courses.

Many will find their way into the Perl Cookbook that should be out
late this spring, so are necessarily copyrighted by me unless otherwise
attributed.  I post them here as a help, and a teaser. :-)

--tom

+---------------------------------------------------------+
| TASK:  Change all isolated oldvar occurrences to newvar |
+---------------------------------------------------------+

    perl -i.old -pe 's{\boldvar\b}{newvar}g' *.[chy]

+---------------------------------------------------+
| TASK:  Increment all numbers found in these files |
+---------------------------------------------------+

    perl i.tiny -pe 's/(\d+)/ 1 + $1 /ge' file1 file2 ....

+------------------------------------------------------------+
| TASK:  Binary edit (careful: only on binary-clean systems) |
+------------------------------------------------------------+

    perl -i.bak -pe 's/Mozilla/Slopoke/g' /usr/local/bin/netscape

+--------------------------------------------------+
| TASK:  Delete all but lines beween START and END |
+--------------------------------------------------+

    perl -i.old -ne 'print unless /^START$/ .. /^END$/' foo.txt

+------------------------------+
| TASK:  Delete first 10 lines |
+------------------------------+

    perl -i.old -ne 'print unless 1 .. 10' foo.txt

+-------------------------------------+
| TASK:  Counting with the wc program |
+-------------------------------------+

    $count = `wc -l < $file`;
    die "wc failed: $?" if $?;
    chomp($count);

    # or simply
    chomp($count = `wc -l < $file`);

+-----------------------------------------------+
| TASK:  Counting lines with a counter variable |
+-----------------------------------------------+

    open(FILE, $file) || die "can't open $file: $!";
    $count = 0;
    $count++ while <FILE>;

+----------------------------------------------------+
| TASK:  Counting paragraphs with a counter variable |
+----------------------------------------------------+

    $/ = '';		# enable paragraph mode for all reads
    open(FILE, $file) || die "can't open $file: $!";
    $paracount = 0;
    $paracount++ while <FILE>;

+-------------------------------+
| TASK:  Counting lines with $. |
+-------------------------------+

    open(FILE, $file) || die "can't open $file: $!";
    (undef) = <FILE>;	# discard all input lines
    # $. now holds the number of lines read.

+------------------------------------+
| TASK:  Counting paragraphs with $. |
+------------------------------------+

    open(FILE, $file) || die "can't open $file: $!";
    $/ = '';
    (undef) = <FILE>;	# discard all input lines
    # $. now holds the number of paragraphs read.

+----------------------------------------+
| TASK:  Reverse the whole file by lines |
+----------------------------------------+

    perl -e 'print reverse <>'              file1 file2 file3 ....

+---------------------------------------------+
| TASK:  Reverse the whole file by paragraphs |
+---------------------------------------------+

    perl -00 -e 'print reverse <>'          file1 file2 file3 ....

+-----------------------------------------------------+
| TASK:  Show each line with its characters backwards |
+-----------------------------------------------------+

    perl -nle 'print scalar reverse $_'     file1 file2 file3 ....

+------------------------------------+
| TASK:  Reverse all bytes in a file |
+------------------------------------+

    perl -0777e 'print scalar reverse <>'   file1 file2 file3 ....

+----------------------------------------------+
| TASK:  Print the last 50 lines (expensively) |
+----------------------------------------------+

    perl -e '@lines = <>; print @lines[$#lines .. $#lines-50]' file1 file2 file3 ....

+-------------------------------------------+
| TASK:  Print the first 50 lines (cheaply) |
+-------------------------------------------+

    perl -pe 'exit if $. > 50'              file1 file2 file3 ....

+--------------------------+
| TASK:  Using clearerr()  |
+--------------------------+

    $naptime = 1;

    use IO::Seekable;   # new in 5.004; before then, it's in POSIX
    open (LOGFILE, "/tmp/logfile") || die "can't open /tmp/logfile: $!";
    for (;;) {
        while (<LOGFILE>) { print }     # or appropriate processing
        sleep $naptime;
        LOGFILE->clearerr();            # clear stdio error flag
    }

+------------------------------------------+
| TASK:  Seeking 0 bytes forward from here |
+------------------------------------------+

    # if you don't have IO::Seekable, instead of clearerr(), try
    seek(LOGFILE, 0, 1);

+------------------------------------+
| TASK:  Seek to where you last read |
+------------------------------------+

    for (;;) {
        for ($curpos = tell(LOGFILE); <LOGFILE>; $curpos = tell(LOGFILE)) {
            # process $_ here
        }
        sleep $naptime;
        seek(LOGFILE, $curpos, 0);  # seek to where we had been
    }

+----------------------------------+
| TASK:  Update a number in a file |
+----------------------------------+

    use Fcntl qw(:DEFAULT :flock);

    sysopen(FH, "numfile", O_RDWR|O_CREAT, 0644)
                             || die "can't open numfile: $!";
    flock(FH, LOCK_EX)       || die "can't write-lock numfile: $!";
    $num = <FH> || 0;
    seek(FH, 0, 0)           || die "can't rewind numfile : $!";
    truncate(FH, 0)          || die "can't truncate numfile: $!";
    (print FH $num+1, "\n")  || die "can't write numfile: $!";
    close FH                 || die "can't close numfile: $!";

+------------------------------------------------+
| TASK:  Lock file with warning about contention |
+------------------------------------------------+

    unless (flock(FH, LOCK_EX|LOCK_NB) ) {
        warn "can't immediately write-lock numfile ($!), blocking...";
        unless (flock(FH, LOCK_EX) ) {
            die "can't get read-lock on numfile: $!";
        }
    }

+-----------------------------------+
| TASK:  Replacement for fortune(1) |
+-----------------------------------+

    $/ = "\n%%\n";
    $data = '/usr/share/games/fortunes';
    srand;
    rand($.) < 1 && ($adage = $_) while <>;
    print $adage;

+-----------------------------------------+
| TASK:  tailwtmp -- watch for new logins |
+-----------------------------------------+

    $typedef = 's x2 i A12 A4 l A8 A16 l'; # linux format
    $sizeof = length pack($typedef, () );

    open(WTMP, '/var/log/wtmp') || die "can't open /var/log/wtmp: $!";
    use IO::File;
    seek(WTMP, 0, SEEK_END);
    for (;;) {
        while (read(WTMP, $buffer, $sizeof) == $sizeof) {
            ($type, $pid,  $line, $id, $time, $user, $host, $addr)
                = unpack($typedef, $buffer);
            next unless $user && ord($user) && $time;
            printf "%1d %-8s %-12s %2s %-24s %-16s %5d %08x\n",
                $type,$user,$line,$id,scalar(localtime($time)),
                $host,$pid,$addr;
        }
        for ($size = -s WTMP; $size == -s WTMP; sleep 1) {}
        WTMP->clearerr();
    }

+------------------------+
| TASK:  Print All Files |
+------------------------+

    @ARGV = qw(.) unless @ARGV;
    use File::Find;
    find sub { print $File::Find::name, -d && '/', "\n" }, @ARGV;

+-------------------------------+
| TASK:  Find Size of Directory |
+-------------------------------+

    use File::Find;
    @ARGV = ('.') unless @ARGV;
    my $sum = 0;
    find sub { $sum += -s }, @ARGV;
    print "@ARGV contains $sum bytes\n";

+--------------------------+
| TASK:  Find Largest File |
+--------------------------+

    use File::Find;
    @ARGV = ('.') unless @ARGV;
    my ($saved_size, $saved_name) = (-1, '');
    sub biggest {
	return unless -s > $saved_size;
	$saved_size = -s _;
	$saved_name = $File::Find::name;
    }
    find(\&biggest, @ARGV);
    print "Biggest file $saved_name in @ARGV is $saved_size bytes long.\n";

+---------------------------+
| TASK:  Find Youngest File |
+---------------------------+

    use File::Find;
    @ARGV = ('.') unless @ARGV;
    my ($age, $name);
    sub youngest {
	return if defined $age && $age > -M;
	$age = (stat(_))[9];
	$name = $File::Find::name;
    }
    find(\&youngest, @ARGV);
    print "$name " . scalar(localtime($age)) . "\n";

+-------------------------+
| TASK:  List Directories |
+-------------------------+

    #!/usr/bin/perl -lw
    @ARGV = qw(.) unless @ARGV;
    use File::Find ();
    sub find(&@) { &File::Find::find }
    *name = \*File::Find::name;
    find { print $name if -d } @ARGV;

+-------------------------------------------------+
| TASK:  Lowercase all filename in this directory |
+-------------------------------------------------+

    opendir(DOT, ".") || die "can't opendir .: $!";
    foreach $old (grep /[A-Z]/, readdir(DOT)) {
	if (($new = lc($old)) ne $old) {
	    rename($old, $new) 
		|| die "can't rename $old to $new: $!";
	}
    }
    closedir(DOT);

+--------------------------------------+
| TASK:  Rename Many Files Arbitrarily |
+--------------------------------------+

    # rename program by Larry Wall
    $op = shift or die "Usage: rename expr [files]\n";
    chomp(@ARGV = <STDIN>) unless @ARGV;
    for (@ARGV) {
	$was = $_;
	eval $op;
	die $@ if $@;
	rename($was,$_) unless $was eq $_;
    }

+---------------------------------------------------+
| TASK:  Get all files, sorted, and with full paths |
+---------------------------------------------------+

    @files = map { "$path/$_" } sort readdir(DIR);

+----------------------------------+
| TASK:  Get just C++ source files |
+----------------------------------+

    @files = grep { /\.(C|cxx|c\+\+)$/ } readdir(DIR);

+----------------------------------+
| TASK:  Just one user's dotfiles  |
+----------------------------------+

    use User::pwent;
    $path = getpwnam($some_user)->dir;
    opendir(DIR, $path);
    @files = grep { /^\./ && !/^\.\.?$/ } readdir(DIR);

+---------------------------------------+
| TASK:  Directories with numeric names |
+---------------------------------------+

    # just directories (short names)
    @dirs = grep { -d "$path/$_" } readdir(DIR);

    # return full paths of directories
    @dirs = grep { -d } 
	    map  { "$path/$_" } 
	    grep { /^\d+$/ }
	    readdir(DIR);

    # same, but sorted numerically
    @dirs = map  { $_->[1] }		    # extract pathnames
	    sort { $a->[0] <=> $b->[0] }    # sort names numeric
	    grep { -d $_->[1] }             # path is a dir
	    map  { [ $_, "$path/$_" ] }     # form (name, path)
	    grep { /^\d+$/ }		    # just numerics
	    readdir(DIR);		    # all files

+----------------------------------+
| TASK:  Backdate a file by a week |
+----------------------------------+

    $SECONDS_PER_DAY = 60 * 60 * 24;
    ($atime, $mtime) = (stat($file))[8,9];
    $atime -= 7 * $SECONDS_PER_DAY;
    $mtime -= 7 * $SECONDS_PER_DAY;

    utime($atime, $mtime, $file) 
	|| die "couldn't backdate $file by a week w/ utime: $!";

+------------------------------------------+
| TASK:  Edit a file without "touching" it |
+------------------------------------------+

    ($atime, $mtime) = (stat($file))[8,9];
    system($ENV{EDITOR} || "vi", $file);  
    utime($atime, $mtime, $file) 
	|| die "couldn't restore $file to orig times: $!";

+------------------------------------------+
| TASK:   locate non-executable text files |
+------------------------------------------+

    local *DIR;		# new handle, lest we recurse
    $dir = "/usr/bin";
    chdir($dir) || die "can't cd to $dir: $!";
    opendir(DIR, ".") || die "can't opendir $path: $!";
    while (defined($file = <DIR>)) {
	if (-f && ! -x _ && -T) {
	    print "$dir/$path\n";
	} 
    } 

+---------------------------------------------------------+
| TASK:  Use Dirhandle to get non-dot plain files, sorted |
+---------------------------------------------------------+

    use DirHandle;
    my $dh = DirHandle->new($dir)   || die "can't opendir $dir: $!";
    @names = sort 		    # sort pathnames
	     grep {    -f     }	    # choose only "plain" files
	     map  { "$dir/$_" }     # create full paths
	     grep {  !/^\./   }     # filter out dot files
	     $dh->read();	    # read all entries


-- 
	Tom Christiansen	tchrist@jhereg.perl.com

    "It is easier to port a shell than a shell script."
		--Larry Wall


------------------------------

Date: 11 Feb 1998 23:13:05 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Expanding Filenames?
Message-Id: <6btba1$46k$2@comdyn.comdyn.com.au>

In article <LADD.98Feb11133258@baldhead.cs.unc.edu>,
	ladd@baldhead.cs.unc.edu (Brian C. Ladd) writes:
> (or whatever it is; I have no way of knowing what the prefix is for every
> user I might want to expand). I have a nasty solution using a spawned ls

perldoc perlfaq5
/How can I translate tildes (~) in a filename

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | If it isn't broken, it doesn't have
Commercial Dynamics Pty. Ltd.       | enough features yet.
NSW, Australia                      | 


------------------------------

Date: 12 Feb 98 00:45:55 GMT
From: devin@premier1.net (Devin L. Ganger)
Subject: Re: FAQless Forays (was: Code Example Needed)
Message-Id: <slrn6e4hfh.506.devin@blacktower.premier1.net>

<flashy-thing!>  Remember only that on Wed, 11 Feb 1998 15:51:19 -0600,
in comp.lang.perl.misc Phil Jach - Reverse to get address wrote:

> The reason I didn't, is because sometimes I have way to many things going
> on.  As most IT professionals know, there is always something to be learned
> and never enough time to read it all.

How hard is it to grep the Perl docs?  How much time does it take to 
do so in the background?  Heck, just a simple scan of the index will tell
a person what the questions in the PerlFAQ are.

> I do read the ng's and I do post replies to some of the easy questions, I
> spend a lot of time searching the Net for my own answers to my Perl
> problems.  That's the best way I've found to learn.  Occasionally I do need
> an answer and I don't have 16 hours to spend researching and testing to
> discover a solution to my Perl problems.

Most questions that are in the FAQ don't require 16 hours of time to fix.

They require a couple of minutes to peruse the FAQ, and if one doesn't quite
understand what it was saying, then one can always post a much more useful
question that asks for an explanation of the not-understood portion of the
FQA.
 
-- 
Devin L. Ganger <devin@premier1.net>
Chief Systems Administrator
Premier1 Internet Services


------------------------------

Date: Wed, 11 Feb 1998 16:17:04 GMT
From: Thomas Strohmaier <thomas.strohmaier@sap-ag.de>
Subject: Filesystem free space under WinNt
Message-Id: <34E1CF00.4604@sap-ag.de>

Hi There
How do I get freespace from a filesystem under WinNt, both FAT and NTFS.	
Best Regards
Samson


------------------------------

Date: 11 Feb 1998 23:21:53 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Help with code
Message-Id: <6btbqh$46k$3@comdyn.comdyn.com.au>

Please read the following information on how to choose a good subject
line:

http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post

In article <6bsf6l$149$1@rclnews.eng.ohio-state.edu>,
	bunner@rclsgi.eng.ohio-state.edu (dan  bunner ) writes:
> I am trying to write a piece of code to be used as a CGI-script.

I hope you're using CGI.pm

> The page is going to send the perl script alot of variables of the type
> var1, var2, var3, var4, var5.
> 
> My script first parses them into an array like structure from the cgi-lib.
> Using ReadParse. So my variables are all in the array $in.

You're not using CGI.pm. Not a good move.

> I read the variables out using $in{var1}.
> 
> What I'd like to be able to do is
> 
> foreach $i (0 .. 5) {
> print "<b> $in{var$i} </b>";
> }

foreach my $i (0 .. 5)
{
	my $var_name = 'var' . $i;
	print "<b> $in{$var_name} </b>";
}

or, more directly

foreach my $i (0 .. 5)
{
	print "<b> $in{'var'.$i} </b>";
}

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | Little girls, like butterflies, need no
Commercial Dynamics Pty. Ltd.       | excuse - Lazarus Long
NSW, Australia                      | 


------------------------------

Date: 11 Feb 1998 22:48:06 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Help!! pattern matching
Message-Id: <6bt9r6$444$1@comdyn.comdyn.com.au>


Please read the following information on how to choose a good subject
line:

http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post


In article <6bsd36$qvg$1@news2.xs4all.nl>,
	"Hans Van Lint" <hvanlint@lodestar.be> writes:
> Sorry to bother you again, but I wanted to explain something:

Again?

> I have a form where you are able to fill in or don't fill in 8 fields.
> When ready, you submit the form.

Errr, yes? Isn't that how it always works? What does this have to do
with perl, or even with the subject?

> 
> In my program I read lines from a text file, and then I look if the fields
> filled in, exist in the resp. fields of the database.
> I want it to look for field AND field AND ...
> So, that's why I write $count++, and when, after checking the 8 fields,
> $count = 8, I can show the record.
> 
> My code looks like this:

Boy, you really should try to format your code a bit more nicely.

[snip]

> Am I correct in thinking when a field is blank it automatically increases
> $count?

That's a bit hard to say. Which field? In most cases, $count gets
incremented when

$somevar =~ /$input{'somename'}/i

In other words, when the contents of somevar match the *regular
expression* in $input{'somename'} in a case insensitive way. You might
consider looking at the quotemeta function, or \Q\E.

a simple test tells us:

# perl -e '$a = "something"; $b = undef; print STDOUT ($a =~ /$b/i) ? "yes\n" : "no\n"'
yes
# perl -e '$a = "something"; $b = ""; print STDOUT ($a =~ /$b/i) ? "yes\n" : "no\n"'
yes
# perl  -e '$a = "something"; $b = "boo"; print STDOUT ($a =~ /$b/i) ? "yes\n" : "no\n"'
no

So that is answered?

> (looking at the outcome it does, so that isn't be the problem I think)
> eg:
>      I fill in one field let's say <ubedrijf> with the value: po
>      I submit my form:
>  What happens is this:
>      When input{'ubedrijf'} doesn't exist in $fbedrijf then it works, count
> = 7
>      But when it does exist, count = 5 when it should be 8!!

Have you tried printing out the values of all those variables, so
that you can compare them manually? have you considered adding in
some hash or something to signify which one doesn't match?

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | Make it idiot proof and someone will
Commercial Dynamics Pty. Ltd.       | make a better idiot.
NSW, Australia                      | 


------------------------------

Date: 11 Feb 1998 16:42:04 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: How Do You Write an Empty While Statement?
Message-Id: <m3en19wt5v.fsf@windlord.Stanford.EDU>

Kevin M Simonson [munged address] writes:

> My job is to write a "perl" script for compiling a large number of
> files.  Those files can be divided into blocks.  Two of the blocks are
> independent of each other; that is, nothing in the one block needs to be
> compiled before anything in the other, and vice versa.  However,
> everything in both blocks need to be compiled before anything in the
> third block can be compiled.

Why don't you just use make?  It was written to do this sort of thing.
There's even a version of make that can distribute compilation across
multiple machines with rsh.

> It seemed like the best way to do that would be to remote shell a job
> from the current job to compile one block, use the current shell to
> compile the other block, and then wait in a loop on the existence of a
> file the other shell created when it finished.

If you have to reinvent the wheel, this is going to be somewhat hard.
You're going to need to fork *somewhere* in this process, whether you do
it yourself or convince the shell to do it for you, and then you're going
to have to worry about what happens with your children.

I'd recommend trying not to invent the wheel.  But in the meantime, to
answer the question on the subject line, you use the syntax:

        1 while (EXPR);

>           #!/usr/local/bin/perl54 -w
>           while (`ls Hmm.Hmm | wc -l < 1`);

This isn't doing anywhere close to what you want it to do.  You're
redirecting the contents of the file named "1" into *something* that may
be ambiguous or an error depending on your shell.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


------------------------------

Date: 12 Feb 1998 00:41:04 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: how to properly interpret a '-?' command line option
Message-Id: <6btgf0$8u1$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, Russ Allbery <rra@stanford.edu> writes:
:Perl variables, for the most part, aren't allowed to contain special
:characters; use the two-argument form of getopts() instead so that the
:options will be stored in a hash.  There are no such limits on hash keys.

While that's a good idea, and I agree, the intrepid perl programmer
would never let a pesky little thing like lexer get in their way . :-)

    # hookopt
    use Getopt::Std;
    getopts('?:');
    if (${"opt_?"}) { print "? set to ${'opt_?'}\n" } 

    jhereg(tchrist)% perl hookopt -\? stuff
    ? set to stuff

You could even do this:

    use Getopt::Std;
    getopts('?:');
    $hook = 'opt_?';
    if ($$hook) { print "? set to $$hook\n" } 

Of course, this is a silly idea.  Forget I even mentioned it. :-)

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com
    Randal said it would be tough to do in sed.  He didn't say he didn't
    understand sed.  Randal understands sed quite well.  Which is why he
    uses Perl.   :-)  -- Larry Wall in <7874@jpl-devvax.JPL.NASA.GOV>


------------------------------

Date: 11 Feb 1998 15:57:59 -0800
From: hermit@cats.ucsc.edu (William R. Ward)
Subject: Re: How to use Mail in Perl ? /$wl007$/
Message-Id: <waad8gtd794.fsf@ese.UCSC.EDU>

wim.lambrechts@NoSPAM-2206.usa.net writes:
> I'm pretty new to Perl, but I would like to use this language to put
> a script on the free.prohosting.com-server (uses Perl 5 in
> #!/usr/bin/perl).  I would like to make a simple program to send me
> some E-mail when someone hits
> http://free.prohosting.com/~wim/cgi-bin/test.pl in his/her browser
> 
> #!/usr/bin/perl
> use Mail::Send;
> $msg->to("wim.lambrechts@no-spam.usa.net");
> $msg->subject("just for testing");
> $msg->close();
> 
> The free.prohosting.com-server also allows to use a POP-mail
> account. Anyone any idea what's causing the server to respond
> 'Internel server error' when launch the script from my browser ?
> Maybe the module 'Mail' (if so: how do I detect whether I can uses
> the module or not ?)  Or does anyone have experience with the
> free.prohosting.com-service ?

Please make sure your news/mail software wraps the text at around 72
characters wide.  I word-wrapped your article when quoting it here.

If your script consists of just those 5 lines above, the answer is
simple: you aren't outputting anything.  A CGI script must output at a
minimum some HTTP headers.  Try adding this to the end of your script:

print << EOF
Content-Type: text/plain

Mail has been sent.
EOF

Then it ought to work....

--Bill.

-- 
William R Ward          Bay View Consulting   http://www.bayview.com/~hermit/
hermit@bayview.com     1803 Mission St. #339        voicemail +1 408/479-4072
hermit@cats.ucsc.edu  Santa Cruz CA 95060 USA           pager +1 408/458-8862
 PGP Key 0x2BD331E5; Public key at http://www.bayview.com/~hermit/pubkey.txt


------------------------------

Date: 12 Feb 1998 00:05:49 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Making Submit buttons into Images
Message-Id: <6btect$qml@fridge.shore.net>

David Walford (davewal@echo.engr.sgi.com) wrote:

: Is there a way to turn the submit buttons into images, but still
: pass along the variable assigned to the button? Any graceful way?

You should really try the Magic module.  It does just about
everything: rotating banners, decrypting things encrypted with
crypt(), server push, code hiding, web counters ... you name it.

Example:

use Magic 'post_cgistuff_elsewhere';
use strict;

my($hocus, $pocus);
$pocus = 'Buddha Belly';

$hocus = Magic->incantation(-button => 'image');
$hocus->Dominocus(-followups_set => $pocus);

:-)

Where is the Perl part of your question, except for saying that you're
writing the script in Perl?

Seriously, please ask your CGI questions over in
comp.infosystems.www.authoring.cgi.

Followups set.

--
Nathan V. Patwardhan


------------------------------

Date: 11 Feb 1998 23:25:34 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Need some help !
Message-Id: <6btc1e$46k$4@comdyn.comdyn.com.au>

Please read the following information on how to choose a good subject
line:

http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post

In article <34E1EDC4.8E17724C@utu.fi>,
	Tarmo Pikaro <tapika@utu.fi> writes:
> Ok here is my problem...
> I'm writing CGI.

I hope you're using CGI.pm

> and I read in like this:
> open (FILE,"somefile") || die "Can't Open file\n";

Always a good idea to include the $! variable in that die message

perldoc perlvar
(look for $!)

If you are using CGI.pm, you can use CGI::Carp to handle this better.

> @XLINES=<FILE>;
> close(FILE);
> $SIZE=@XLINES;
>   for ($i=0;$i<=$SIZE;$i++) {
>      $recipient=$XLINES[$i];

Very unperlian, and not the most efficient.

foreach $recipient (@XLINES)
{
	# do whatever you need to do
}

> and at this point I have string with enter at the end.
> How can I convert - so there wont ne any enter ??????????

Look at the chomp() function

perldoc -f chomp

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | The gene pool could use a little
Commercial Dynamics Pty. Ltd.       | chlorine.
NSW, Australia                      | 


------------------------------

Date: 11 Feb 1998 16:33:27 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Negative of a minus sign is a plus?
Message-Id: <m3n2fxwtk8.fsf@windlord.Stanford.EDU>

Shimpei Yamashita writes:

> I'm not completely sure about why, but it *is* documented in
> perlop(1):

>        Unary "-" performs arithmetic negation if the operand is numeric.
>        If the operand is an identifier, a string consisting of a minus
>        sign concatenated with the identifier is returned.  Otherwise, if
>        the string starts with a plus or minus, a string starting with
>        the opposite sign is returned.  One effect of these rules is that
>        -bareword is equivalent to "-bareword".

Possibly because there are various modules that take arguments in a
"switch-like" form and this makes it easier to write -switch arguments?

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


------------------------------

Date: 12 Feb 1998 00:18:28 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: New Perl book reviews
Message-Id: <6btf4k$pb1@mozo.cc.purdue.edu>

petdance@maxx.mc.net (Andy Lester) writes:

}hmmm, it seems like nobody's reading the paragraph parts of my page.

This is comp.lang.perl.misc.  Nobody reads the man page, the camel,
the web site(s), or the FAQ, or even the responses to their own posts.

Your page should fit in just fine.

P.S. In the spirit of this post, I didn't visit your page.

-- 
Mike Gebis  gebis@ecn.purdue.edu  mgebis@eternal.net


------------------------------

Date: Wed, 11 Feb 1998 23:30:05 GMT
From: stephenc@granddesign.com (Stephen P. Clouse)
Subject: Re: Possible bug in "or" operator
Message-Id: <34e23311.653122@news2.kc.net>


Hash: SHA1

On 11 Feb 1998 21:53:59 GMT in message <<6bt6ln$2vm@news.service.uci.edu>
comp.lang.perl.misc>, ehood@medusa.acs.uci.edu (Earl Hood) wrote:

>    $x = 0 || 5;
>    $y = 0 or 5;
>    print "$x, $y\n";
>    if ($y) {
>	print "$y => TRUE\n";
>    }
>    if (0 or 5) {
>	print "0 or 5 => TRUE\n";
>    }
>
>The output is:
>
>    5, 0
>    0 or 5 => TRUE
>
>Why doesn't $y get the value of 5?  I have noticed this behavior
>in older version of perl 5 also.  At the least, it should get
>a value that is interpreted by Perl as a true value so the if
>test on $y will not fail.

I'd go back and look at your operator precedence table.  = binds looser than ||
but tighter than or.  Thus:

1. In the $x line, the || has higher precedence, so it gets evaluated first; the
   result is 5, which then gets passed to the = operator and sets $x.
2. In the $y line, the = has higher precedence, so the first thing that happens
   is $y = 0, whose output is then shoved off to the or operator, which is now
   in a void context, so your 5 vanishes.

Down in the if statement, or is the only operator present, so it evaluates
exactly like you think it would.  To get the same output with = present the or
needs to be parenthesized so it gets evaluated first, making the line "$y = (0
or 5)".

Or, just use || :)

- -- 
Stephen P. Clouse
stephenc@granddesign.com -- steve@warpcore.org -- UIN 135012
Grand Design, Inc. (http://www.granddesign.com) -- Quality Business Web Design
The Warp Core (http://www.warpcore.org) -- The Web's Premier Descent Site
PGP-Encrypted E-Mail Preferred (Key available at www.granddesign.com/~stephenc)
Fight Spam/UCE -- http://www.cauce.org


Version: PGP for Business Security 5.5

iQA/AwUBNOI0XWOLD55Fj/ZkEQJMoACg4rgMHFC7VgRVlMqQhT1lOIu9TtQAoMc9
f8lO7Tp0WP8qerxBuhi3IpWN
=D4M6
-----END PGP SIGNATURE-----



------------------------------

Date: 12 Feb 1998 00:39:56 GMT
From: ehood@medusa.acs.uci.edu (Earl Hood)
Subject: Re: Possible bug in "or" operator
Message-Id: <6btgcs$aek@news.service.uci.edu>

In article <6bt6ln$2vm@news.service.uci.edu>,
Earl Hood <ehood@medusa.acs.uci.edu> wrote:
>Take the following code example:
>
>    $x = 0 || 5;
>    $y = 0 or 5;
>    print "$x, $y\n";
>    if ($y) {
>	print "$y => TRUE\n";
>    }
>    if (0 or 5) {
>	print "0 or 5 => TRUE\n";
>    }

Excuse my temporary stupidity that Tom kindly pointed out (forgot
-w and precedence):

    $y = 0 or 5;

gets interpreted as:

    ($y = 0) or 5;

I agree with Tom's assessment of the "and" and "or" operators.

	--ewh
-- 
             Earl Hood              | University of California: Irvine
      ehood@medusa.acs.uci.edu      |      Electronic Loiterer
http://www.oac.uci.edu/indiv/ehood/ | Dabbler of SGML/WWW/Perl/MIME


------------------------------

Date: 11 Feb 1998 23:58:40 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: PUZZLE: Answer me these questions three
Message-Id: <6btdvg$2c4$11@csnews.cs.colorado.edu>

Question 1: Is this program recursive?
Question 2: How many hashes does it use?
Question 3: What are the names of these hashes?

    # feed `find -ls` into this to translate
    # 204814    4 -rw-------   1 tchrist  wheel        3776 Feb  4 ...
    # into something like this
    # 204814    4 -rw-------   1 101      0            3776 Feb  4 ...
    # 
    $fmt = 'a26 A9 A8 a*';
    while (<>) {
	($pre, $login, $group, $post) = unpack($fmt, $_);
	print pack($fmt, $pre, &id(*login), &id(*group), $post);
    }
    sub id {
	local(*id) = @_;
	$id{$id} = $id =~ /^\d+$/ ? $id : &id       unless defined $id{$id};
	$id{$id};
    }
    sub login { (getpwnam($id))[2]; }
    sub group { (getgrnam($id))[2]; }

--tom

-- 
	Tom Christiansen	tchrist@jhereg.perl.com

    Though I'll admit readability suffers slightly... 
                    --Larry Wall in <2969@jato.Jpl.Nasa.Gov>


------------------------------

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 1866
**************************************

home help back first fref pref prev next nref lref last post