[23148] in Perl-Users-Digest
Perl-Users Digest, Issue: 5369 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 15 21:05:49 2003
Date: Fri, 15 Aug 2003 18:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 15 Aug 2003 Volume: 10 Number: 5369
Today's topics:
Re: Finding 'path to perl' of remote server (Randal L. Schwartz)
How to create an array from a string? (Francesco Moi)
Re: How to create an array from a string? <noreply@gunnar.cc>
Re: How to express "not followed by"? <spamblock@junkmail.com>
Re: How to express "not followed by"? <spamblock@junkmail.com>
Re: How to express "not followed by"? <noreply@gunnar.cc>
Re: How to express "not followed by"? (Randal L. Schwartz)
Re: How to express "not followed by"? <skuo@mtwhitney.nsc.com>
Newbie: How to read metadata from a windows DLL <fozzie_beer@hotmail.com>
Re: regex diffs between perl 5.6.1 and 5.8.0? <Patrick_member@newsguy.com>
Seeking critique of simple file line numbering code. <spamblock@junkmail.com>
Re: Seeking critique of simple file line numbering code <uri@stemsystems.com>
Re: Seeking critique of simple file line numbering code <bharn_S_ish@te_P_chnologi_A_st._M_com>
Re: Seeking critique of simple file line numbering code <michael.p.broida@boeing.com>
syscall question/example <stop.spam@whitehouse.gov>
Re: syscall question/example <uri@stemsystems.com>
Re: syscall question/example <stop.spam@whitehouse.gov>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 15 Aug 2003 11:47:59 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Finding 'path to perl' of remote server
Message-Id: <0fe170f5854f070b280708f59b06a0cd@news.teranews.com>
>>>>> "Rafael" == Rafael Garcia-Suarez <rgarciasuarez@free.fr> writes:
Rafael> Perhaps a solution to your problem is to put
Rafael> #!/usr/bin/env perl
Rafael> at the 1st line of your perl programs (if you have env(1)). See the
Rafael> perlrun manpage.
Except that env(1) isn't portable, and on a few systems, they put
it into /usr/ucb (or was it /bin?) instead of /usr/bin!
Gah.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 15 Aug 2003 16:33:41 -0700
From: francescomoi@europe.com (Francesco Moi)
Subject: How to create an array from a string?
Message-Id: <5b829932.0308151533.18c7de64@posting.google.com>
Hello.
I would like to create an array from a string. I tried with:
---------------------------
$string = "1 2 3";
@array1 = [1,2,3];
@array2 = split(/\s/, $string);
print $array1[0] . " - " . $array1[1] . " - " . $array1[2] . "\n";
print $array2[0] . " - " . $array2[1] . " - " . $array2[2] . "\n";
---------------------------
But I get:
----------------------------
ARRAY(0x1674e9c) - -
1 - 2 - 3
-----------------------------
I would like to generate an array of the same type of 'array1' from
'string'. Is it possible?
Thank you very much.
------------------------------
Date: Sat, 16 Aug 2003 01:44:45 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to create an array from a string?
Message-Id: <bhjr9r$c7ck$1@ID-184292.news.uni-berlin.de>
Francesco Moi wrote:
>
> @array1 = [1,2,3];
------------^-----^
Hmm.. Don't you mean:
@array1 = (1,2,3);
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 15 Aug 2003 15:23:09 -0700
From: "David Oswald" <spamblock@junkmail.com>
Subject: Re: How to express "not followed by"?
Message-Id: <vjqnr53jt9vba@corp.supernews.com>
"Tore Aursand" <tore@aursand.no> wrote in message
news:pan.2003.08.15.21.13.38.329532@aursand.no...
> On Fri, 15 Aug 2003 13:49:04 -0700, Yi Mang wrote:
> > My question is regarding to the regexp "not followed by", for example,
> > if a string has a number followed by a semi-colon, then pass;
> > otherwise, print an error.
>
> Hmm. If I understand you right, the solution should be pretty
> straightforward?
>
> if ( /\d;/ ) {
> # Pass
> }
> else {
> # Error
> }
Actually you've just matched only one digit, and included the semicolon in
the match. Of course he didn't specify if the semicolon sould be part of
the match or not, or if it was just a criteria for matching.
Previously I incorrectly stated that /\d+(?!;)/ would work, but I misread
his strategy. I somehow missed where he said that semicolon SHOULD match.
With that in mind, it seems that his match, as described in the above
paragraph, could be written as:
/\d+;/ if he wants the semicolon actually included in the matched text, or
/\d+(?=;)/ if he only wants the semicolon to be a condition of the match,
but not included in what gets matched.
Dave
------------------------------
Date: Fri, 15 Aug 2003 15:32:32 -0700
From: "David Oswald" <spamblock@junkmail.com>
Subject: Re: How to express "not followed by"?
Message-Id: <vjqo7h16rqbp6d@corp.supernews.com>
"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:bhjkjr$aa4h$1@ID-184292.news.uni-berlin.de...
> David Oswald wrote:
> > The regexp could look something like this:
> >
> > /\d+(?!;)/
> >
> > That would match one or more numeric digits ...
> -------------------^^^^^^^^^^^
>
> Yes... And it would match 'abc123;edf' just fine - for the same reason
> as OP's /\d+[^;]/ matches, i.e. "one or more".
>
> So your solution cannot work.
>
> If the number of digits is fixed, it's easy: Then both /\d{3}[^;]/ and
> /\d{3}(?!;)/ fails.
Actually I misread his request. Now that I re-read what he was looking for,
I understand him to mean that numeric digits followed by a semicolon should
pass, but numeric digits not followed by a semicolon should not match.
I'm not sure why you're limiting the number of numeric digits. But here's
my second stab at getting it right:
/\d+(?=;)/ will match any string where any number of one or more digits is
followed by a semicolon, but will not match if the numeric digits are not
followed by a semicolon. In this case, the semicolon is not part of the
match, but rather, a criteria of the match. That means that $& will contain
the numeric digits, but not the semicolon.
If he wanted to keep the semicolon, then a lookahead isn't even necessary.
In that case, the match could be:
/\d+;/ Now I'm specifying that one or more digits will match if followed by
a semicolon. If not followed by a semicolon, there won't be a match.
His subject line states "not followed by", but what he's really asking seems
to be "followed by", since his first paragraph states what the number should
be followed by, not what it shouldn't be followed by, except that it
shouldn't be followed by anything else.
If, on the other hand, he intends for a match to occur at end of line
without semicolon, or anywhere in the line with a semicolon, that's a
different beast, and could be written as follows:
/(\d+$)|(\d+;)/
or with lookahead:
/(\d+$)|(\d+(?=;))/
The second option would require that the semicolon appear if the number is
not at the end of line, but wouldn't capture the semicolon into the match.
Dave
------------------------------
Date: Sat, 16 Aug 2003 01:20:32 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to express "not followed by"?
Message-Id: <bhjpse$be8n$1@ID-184292.news.uni-berlin.de>
David Oswald wrote:
> here's my second stab at getting it right:
>
> /\d+(?=;)/ will match any string where any number of one or more
> digits is followed by a semicolon, but will not match if the
> numeric digits are not followed by a semicolon. In this case, the
> semicolon is not part of the match, but rather, a criteria of the
> match. That means that $& will contain the numeric digits, but not
> the semicolon.
>
> If he wanted to keep the semicolon, then a lookahead isn't even
> necessary. In that case, the match could be:
> /\d+;/ Now I'm specifying that one or more digits will match if
> followed by a semicolon. If not followed by a semicolon, there
> won't be a match.
/\d+(?=;)/ is basically just a more complicated way to write /\d+;/,
and if you are not making use of the $& variable, there is no reason
to bother with a zero-width assertion, is there?
> His subject line states "not followed by", but what he's really
> asking seems to be "followed by", since his first paragraph states
> what the number should be followed by, not what it shouldn't be
> followed by, except that it shouldn't be followed by anything else.
Precisely.
> If, on the other hand, he intends for a match to occur at end of
> line without semicolon, or anywhere in the line with a semicolon,
> that's a different beast, and could be written as follows:
>
> /(\d+$)|(\d+;)/
>
> or with lookahead:
> /(\d+$)|(\d+(?=;))/
Or shorter:
/\d+(?:;|$)/
> The second option would require that the semicolon appear if the
> number is not at the end of line, but wouldn't capture the
> semicolon into the match.
Rather than thinking of what's captured in the $& variable, I pay
usually more attention to whether things are captured in the $1, $2,
etc. variables. Both your last options would capture the whole match
in either $1 or $2 ...
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 15 Aug 2003 11:33:07 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: How to express "not followed by"?
Message-Id: <56c706049f0528f44bf8a2536a502ad4@news.teranews.com>
>>>>> "Yi" == Yi Mang <yi_mang@yahoo.com> writes:
Yi> My question is regarding to the regexp "not followed by", for example,
Yi> if a string has a number followed by a semi-colon, then pass;
Yi> otherwise, print an error.
It's hard to tell what your "otherwise" applies to, since the rule can
be interpreted as either:
IF has number THEN
IF number IS followed by semi THEN - PASS
ELSE - FAIL
ELSE - FAIL
Or perhaps
IF has number THEN
IF number IS followed by semi THEN - PASS
ELSE - FAIL
ELSE - PASS
Which is it?
And there's the definition of "number". Do you mean "single digit",
or "sequence of digits"?
Perhaps you should clarify the rule, and also give some examples.
Any answers you get until you've done that are stabbing in the dark.
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Fri, 15 Aug 2003 17:04:40 -0700
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: How to express "not followed by"?
Message-Id: <Pine.GSO.4.21.0308151657010.5972-100000@mtwhitney.nsc.com>
On 15 Aug 2003, Yi Mang wrote:
> Hi,
> My question is regarding to the regexp "not followed by", for example,
> if a string has a number followed by a semi-colon, then pass;
> otherwise, print an error. This is what I have constructed:
> if ( /\d+([^;]) ) # A number followed by non-semicolon
> {
> print "error\n";
> }
> else
> {
> print "pass\n";
> }
>
> I tested this on the following string "abc123;edf", it's supposed to
> pass, but it did not. It turned out that the expression thinks 12
> followed 3, not semicolon, so it's an error. I get around around this
> problem if I constructed the if statement this way:
> if ( /\d+([^;0123456789]) )
>
> but I think there should be an easy way to do this. Could you help me
> out?
(snipped)
You want to avoid backtracking?
Use the (?>) extended pattern (see perldoc perlre).
For example:
$_ = 'abc123;edf';
if (/(\d+)([^;])/) {
print "Digit(s) ($1) followed by something other than ; ($2)\n";
print "Accomplished by backtracking\n";
}
# compared to
if (/((?>\d+))([^;])/) {
print "Matches one or more digits ($1) followed by something other than ; ($2)\n";
print "No backtracking allowed\n";
}
--
Hope this helps,
Steven
------------------------------
Date: Fri, 15 Aug 2003 17:29:03 -0700
From: "Frank Foss" <fozzie_beer@hotmail.com>
Subject: Newbie: How to read metadata from a windows DLL
Message-Id: <bhjtsa$b4fd$1@ID-190416.news.uni-berlin.de>
Greetings!
If you will forgive a newbie, I'll try to explain what I want to do.
(Googling wasn't really successful in this case, since I don't know where to
begin.)
My company is making software, and part of the release notes are details
about the files included in the release, timestamp, version, checksum, and
so on. This info is gathered in a very manual process:
In Windows Explorer, highlighting the file, ALT+Enter to bring up a
"Properties" window.
In this window, there are tabs, "General","Version", and so on.
What I would like to do, is to write a quick Perl script that will traverse
a directory,
look "inside" each .DLL or what ever type of file, read the metadata
attributes, and write to a file.
I am using ActiveState Perl, 5.6.1 on Windows 2000.
Guess my questions are:
Is there a Perl module that allows me to read this info from the files?
What methods to use?
Examples of code to do this?
Module to compute checksums?
Thanks in advance,
Foz
------------------------------
Date: 15 Aug 2003 15:21:14 -0700
From: Patrick Flaherty <Patrick_member@newsguy.com>
Subject: Re: regex diffs between perl 5.6.1 and 5.8.0?
Message-Id: <bhjmcq0o9i@drn.newsguy.com>
In article <3f3c9ebc.301200988@news.erols.com>, Jay Tilton says...
>
>Patrick Flaherty <Patrick_member@newsguy.com> wrote:
>
>: Back in 5.6.1, the following succeeded in stripping out all x1a garbage chars
>: from a set of files:
>:
>: perl -p0777 -i.bu -e 's/\X1a+$//g' house.lis
>:
>: I run the same thing under 5.8.0 and it has no effect.
>
>Case matters. "\X1a" is not the same thing as "\x1a".
>"\X" in a regex has its own special meaning.
>
>If that code worked as expected in 5.6.1., it probably shouldn't have.
>The difference in behavior between 5.6.1 and 5.8.0 would be because of
>a bug fix, though I'm not seeing it right away in the delta docs.
>
Thanx Jay,
Actually my original code _is_ a lower-case x. The upper case in the above was
some stuff I was experimenting with. So I don't think this is the problem I'm
having.
pat
------------------------------
Date: Fri, 15 Aug 2003 15:14:08 -0700
From: "David Oswald" <spamblock@junkmail.com>
Subject: Seeking critique of simple file line numbering code.
Message-Id: <vjqn57oqptch73@corp.supernews.com>
I realize that grep performs some of this same functionality, but I just
wanted to create the tool on my own for the experience. To that end, I'm
also interested in hearing how I might clean it up from every standpoint
(style, robustness, etc.). This script reads infile, prepends a line number
to each line in the file, and outputs it as outfile. Come to think of it, I
probably should have just written the output to stdout to make it easier to
redirect from the shell. But this is just for discussion's sake.
It's pretty basic, and the comments within the file should tell what's going
on.
#!/usr/bin/perl
# Usage:
# linenum [-s] infile [outfile]
# linenum writes outfile with line numbers prepended
# to each line in infile.
# The -s flag causes line numbers in the format of /^d+:/
# to be stripped. Use -s to un-do what was done
# by linenum.
use strict;
use warnings;
# Strip and save command line switches.
my @switch;
foreach ( @ARGV ) {
if ( $_ =~ /^-(.)/ ) {
push @switch, $1;
shift @ARGV;
}
}
# Check for -s switch.
my $remove_numbers = 0;
foreach ( @switch ) {
if ( $_ eq "s" ) {
$remove_numbers = 1;
} else {
print "Invalid option, -$_.\n";
print "Usage: linenum.pl [-s] infile [outfile]\n";
exit;
}
}
# Pull in the filenames.
my ( $infile, $outfile ) = @ARGV;
# If outfile wasn't specified, make up a name.
$outfile = $outfile || $infile.".out";
# Test for file existances.
unless ( -e $infile ) {
print "$infile doesn't exist.\n";
print "Exiting.\n";
exit;
}
if ( -e $outfile ) {
print "$outfile already exists\n";
print "Overwrite? [Y/N]: ";
if (my $decision = <STDIN> !~ /^[yY]/) {
print "Aborting.\n";
exit;
}
}
# Open the files.
open ( INFILE, "<$infile" ) or
die "Unable to open $infile.\n$!";
open ( OUTFILE, ">$outfile" ) or
die "Unable to open $outfile.\n$!";
# Start the counter, and process the files.
my $count = 0;
while ( <INFILE> ) {
# If the remove_numbers flag isn't set,
# increment the counter, prepend number.
unless ( $remove_numbers ) {
$count++;
$_ = "$count: ".$_;
} else {
# Otherwise strip number prefixes.
$_ =~ s/^\d+://;
}
print OUTFILE $_;
}
# Sweep up, turn out the lights, lock the
# door on the way out.
close ( INFILE ) or
die "Unable to close $infile.\n$!";
close ( OUTFILE ) or
die "Unable to close $outfile.\n$!";
--
DJO
------------------------------
Date: Fri, 15 Aug 2003 22:56:23 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Seeking critique of simple file line numbering code.
Message-Id: <x7oeyqttrc.fsf@mail.sysarch.com>
>>>>> "DO" == David Oswald <spamblock@junkmail.com> writes:
DO> use strict;
DO> use warnings;
good start
DO> # Strip and save command line switches.
DO> my @switch;
DO> foreach ( @ARGV ) {
DO> if ( $_ =~ /^-(.)/ ) {
no need for $_ as it is the default bound value for m//
DO> push @switch, $1;
DO> shift @ARGV;
DO> }
DO> }
bad switch handling. either use a standard module or a cpan one. perl
even has simple switch handling with the -s option (see perlrun) but you
would have to deal with a package global that way.
DO> # Check for -s switch.
DO> my $remove_numbers = 0;
DO> foreach ( @switch ) {
DO> if ( $_ eq "s" ) {
DO> $remove_numbers = 1;
DO> } else {
DO> print "Invalid option, -$_.\n";
DO> print "Usage: linenum.pl [-s] infile [outfile]\n";
use a here doc to print multiple lines. that way you see what you get
and you lose the quotes and\n noise.
DO> exit;
DO> }
DO> }
blech. again, a standard arg parsing module is best. the good ones work
with a hash ref so you can keep strict clean. then you have 2 lines, one
to call the module and one to set $remove_numbers from $opts{'s'}.
DO> # Pull in the filenames.
DO> my ( $infile, $outfile ) = @ARGV;
DO> # If outfile wasn't specified, make up a name.
DO> $outfile = $outfile || $infile.".out";
$outfile ||= "$infile.out";
DO> # Test for file existances.
DO> unless ( -e $infile ) {
DO> print "$infile doesn't exist.\n";
DO> print "Exiting.\n";
here doc to the rescue again. multiple prints in a row are fugly and slower.
DO> exit;
why not call die with the error message?
-e $infile or die <<DIE ;
$infile doesn't exist.
Exiting.
DIE
DO> if ( -e $outfile ) {
DO> print "$outfile already exists\n";
DO> print "Overwrite? [Y/N]: ";
you may not see that question as it doesn't end in a newline and won't
get flushed. set $| to make sure that works. see perlvar for info on $|.
DO> if (my $decision = <STDIN> !~ /^[yY]/) {
unless (my $decision = <STDIN> =~ /^y/i ) {
use unless and rarely use !~. it is clearer. and the /i modifier
eliminates the need for the char class
DO> # Open the files.
DO> open ( INFILE, "<$infile" ) or
DO> die "Unable to open $infile.\n$!";
DO> open ( OUTFILE, ">$outfile" ) or
DO> die "Unable to open $outfile.\n$!";
DO> # Start the counter, and process the files.
DO> my $count = 0;
DO> while ( <INFILE> ) {
DO> # If the remove_numbers flag isn't set,
DO> # increment the counter, prepend number.
DO> unless ( $remove_numbers ) {
DO> $count++;
DO> $_ = "$count: ".$_;
DO> } else {
DO> # Otherwise strip number prefixes.
DO> $_ =~ s/^\d+://;
again, no need for $_ there.
DO> }
DO> print OUTFILE $_;
same is true here. print defaults to $_.
DO> }
overall it is ok. some minor style issues and nothing very buggy at
first glance. but then it doesn't do much. :)
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Fri, 15 Aug 2003 23:22:50 GMT
From: Brian Harnish <bharn_S_ish@te_P_chnologi_A_st._M_com>
Subject: Re: Seeking critique of simple file line numbering code.
Message-Id: <pan.2003.08.15.23.23.26.441824@te_P_chnologi_A_st._M_com>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
On Fri, 15 Aug 2003 15:14:08 -0700, David Oswald wrote:
> I realize that grep performs some of this same functionality, but I just
> wanted to create the tool on my own for the experience. To that end, I'm
> also interested in hearing how I might clean it up from every standpoint
> (style, robustness, etc.). This script reads infile, prepends a line number
> to each line in the file, and outputs it as outfile. Come to think of it, I
> probably should have just written the output to stdout to make it easier to
> redirect from the shell. But this is just for discussion's sake.
>
> It's pretty basic, and the comments within the file should tell what's going
> on.
Its pretty good. Instead of $count, you can use $. (its the line number).
Programs like this also become much simpler when ran using stdin and
stdout:
perl -wpe 's/^/$.: /' < infile > outfile
perl -wpe 's/^$.: //' < infile > outfile
or even:
#!/usr/bin/perl -wp
BEGIN {
use strict;
use Getopt::Std;
use vars qw/%opts/;
getopts('s', \%opts);
}
$opts{s} ? s/^$.: // : s/^/$.: /
__END__
- Brian
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQE/PWtdiK/rA3tCpFYRAhi0AJ4mF9vsdzs5XKkB+qmsGW11EoWgPwCeKV7R
MoPjq18u5V7f/CyG0pRGMqI=
=YW+B
-----END PGP SIGNATURE-----
------------------------------
Date: Fri, 15 Aug 2003 23:42:57 GMT
From: "Michael P. Broida" <michael.p.broida@boeing.com>
Subject: Re: Seeking critique of simple file line numbering code.
Message-Id: <3F3D7001.ED4C3547@boeing.com>
David Oswald wrote:
>
> I realize that grep performs some of this same functionality, but I just
> wanted to create the tool on my own for the experience. To that end, I'm
> also interested in hearing how I might clean it up from every standpoint
> (style, robustness, etc.). This script reads infile, prepends a line number
> to each line in the file, and outputs it as outfile. Come to think of it, I
> probably should have just written the output to stdout to make it easier to
> redirect from the shell. But this is just for discussion's sake.
>
> It's pretty basic, and the comments within the file should tell what's going
> on.
>
> #!/usr/bin/perl
>
> # Usage:
> # linenum [-s] infile [outfile]
>
> # linenum writes outfile with line numbers prepended
> # to each line in infile.
>
> # The -s flag causes line numbers in the format of /^d+:/
> # to be stripped. Use -s to un-do what was done
> # by linenum.
>
> use strict;
> use warnings;
>
> # Strip and save command line switches.
>
> my @switch;
> foreach ( @ARGV ) {
> if ( $_ =~ /^-(.)/ ) {
> push @switch, $1;
> shift @ARGV;
> }
> }
>
> # Check for -s switch.
>
> my $remove_numbers = 0;
> foreach ( @switch ) {
> if ( $_ eq "s" ) {
> $remove_numbers = 1;
> } else {
> print "Invalid option, -$_.\n";
> print "Usage: linenum.pl [-s] infile [outfile]\n";
> exit;
> }
> }
>
> # Pull in the filenames.
>
> my ( $infile, $outfile ) = @ARGV;
>
> # If outfile wasn't specified, make up a name.
>
> $outfile = $outfile || $infile.".out";
>
> # Test for file existances.
>
> unless ( -e $infile ) {
> print "$infile doesn't exist.\n";
> print "Exiting.\n";
> exit;
> }
>
> if ( -e $outfile ) {
> print "$outfile already exists\n";
> print "Overwrite? [Y/N]: ";
> if (my $decision = <STDIN> !~ /^[yY]/) {
> print "Aborting.\n";
> exit;
> }
> }
>
> # Open the files.
>
> open ( INFILE, "<$infile" ) or
> die "Unable to open $infile.\n$!";
>
> open ( OUTFILE, ">$outfile" ) or
> die "Unable to open $outfile.\n$!";
>
> # Start the counter, and process the files.
>
> my $count = 0;
> while ( <INFILE> ) {
> # If the remove_numbers flag isn't set,
> # increment the counter, prepend number.
> unless ( $remove_numbers ) {
> $count++;
> $_ = "$count: ".$_;
> } else {
> # Otherwise strip number prefixes.
> $_ =~ s/^\d+://;
> }
> print OUTFILE $_;
> }
>
> # Sweep up, turn out the lights, lock the
> # door on the way out.
> close ( INFILE ) or
> die "Unable to close $infile.\n$!";
>
> close ( OUTFILE ) or
> die "Unable to close $outfile.\n$!";
From another thread, I've recently learned that $.
(dollar dot) contains the line number from your
input file. You don't have to keep your own
$count variable.
(Lots of good learnin' in this group. :)
Mike
------------------------------
Date: Fri, 15 Aug 2003 21:51:54 GMT
From: "Robert" <stop.spam@whitehouse.gov>
Subject: syscall question/example
Message-Id: <HJoKqF.58z@news.boeing.com>
Greetings,
I am trying to use syscall to execute system calls on my HP-UX server. I
was able to get the Cookbook example to work after some corrections. But I
need to call the pstat functions. Does anyone have any examples of scripts
using syscall or tell me where I can look (other than perldoc -f syscall)
for a better understanding of the syntax? Thanx in advance.
------------------------------
Date: Fri, 15 Aug 2003 22:45:38 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: syscall question/example
Message-Id: <x7r83mtu99.fsf@mail.sysarch.com>
>>>>> "R" == Robert <stop.spam@whitehouse.gov> writes:
R> I am trying to use syscall to execute system calls on my HP-UX
R> server. I was able to get the Cookbook example to work after some
R> corrections. But I need to call the pstat functions. Does anyone
R> have any examples of scripts using syscall or tell me where I can
R> look (other than perldoc -f syscall) for a better understanding of
R> the syntax? Thanx in advance.
some of the core perl modules use syscall. in particular i have seen it
use in Sys::Hostname. i wouldn't be surprised to see it used in other
Sys:: modules. look at their source code for how to use syscall. it
isn't that complicated.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Fri, 15 Aug 2003 23:50:14 GMT
From: "Robert" <stop.spam@whitehouse.gov>
Subject: Re: syscall question/example
Message-Id: <HJoq7o.9nv@news.boeing.com>
thanx
"Uri Guttman" <uri@stemsystems.com> wrote in message
news:x7r83mtu99.fsf@mail.sysarch.com...
> >>>>> "R" == Robert <stop.spam@whitehouse.gov> writes:
>
> R> I am trying to use syscall to execute system calls on my HP-UX
> R> server. I was able to get the Cookbook example to work after some
> R> corrections. But I need to call the pstat functions. Does anyone
> R> have any examples of scripts using syscall or tell me where I can
> R> look (other than perldoc -f syscall) for a better understanding of
> R> the syntax? Thanx in advance.
>
> some of the core perl modules use syscall. in particular i have seen it
> use in Sys::Hostname. i wouldn't be surprised to see it used in other
> Sys:: modules. look at their source code for how to use syscall. it
> isn't that complicated.
>
> uri
>
> --
> Uri Guttman ------ uri@stemsystems.com --------
http://www.stemsystems.com
> --Perl Consulting, Stem Development, Systems Architecture, Design and
Coding-
> Search or Offer Perl Jobs ----------------------------
http://jobs.perl.org
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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.
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 V10 Issue 5369
***************************************