[7242] in Perl-Users-Digest
Perl-Users Digest, Issue: 867 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 14 14:18:52 1997
Date: Thu, 14 Aug 97 11:00:22 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 14 Aug 1997 Volume: 8 Number: 867
Today's topics:
Re: arrays <rootbeer@teleport.com>
Re: CGI: Forms RADIO BUTTONS <rootbeer@teleport.com>
Re: comparing for a range of number - easiest way to do (Terry Michael Fletcher - PCD ~)
Re: converting from hex <" darrell_johnson"@nmisq2.miss.nt.com>
Fork error in open() (Ken Ficara)
Re: incredibly simple question (Mike Stok)
Re: incredibly simple question (Steve O'Hara Smith)
Re: incredibly simple question (Dick Chimenti)
Re: Interaction between \Q and variable interpolation - <rootbeer@teleport.com>
Re: Need help accessing tty modem devices within perl!! (Matthew H. Gerlach)
Re: Need help! <rootbeer@teleport.com>
Re: New User Question on FTP (Ed Vielmetti)
Re: NO-DELAY READ ON FIFO <psrc@corp.airmedia.com>
Overriding Functions in Modules, i.e. File::Find lstat (Stuart Poulin)
Re: Perl and HTML <rootbeer@teleport.com>
Re: perl output destroys hard drive ? (Doug McLaren)
Re: perl output destroys hard drive ? <rootbeer@teleport.com>
Re: Puting pattern in a variable (Bob Wilkinson)
Re: Setting Groupid <rootbeer@teleport.com>
Re: Simple question on s/// operator in expressions (brian d foy)
Re: Simple question on s/// operator in expressions <rootbeer@teleport.com>
Re: sorting... <lilly@fedex.com>
Re: sorting... <rootbeer@teleport.com>
Uninitialized Value? Really? (Jeff Stampes)
Re: Variable substitution into a regexp <rootbeer@teleport.com>
Re: version of Perl5 for NT4 <garyng@ibm.net>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 14 Aug 1997 10:11:47 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: David Siebert <dsiebert@gate.net>
Subject: Re: arrays
Message-Id: <Pine.GSO.3.96.970814101010.8293Q-100000@julie.teleport.com>
On 13 Aug 1997, David Siebert wrote:
> Subject: arrays
Please check out this helpful information on choosing good subject
lines. It will be a big help to you in making it more likely that your
requests will be answered.
http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post
> is there an esy function to find the length of an array?
$number_of_elements = @my_array;
Note that you can't (in general) use this method on functions or
expressions which return a list. (See any good Perl book's information on
scalar vs. list context.) Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Thu, 14 Aug 1997 10:04:15 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Shaun O'Shea <lmisosa@eei.ericsson.se>
Subject: Re: CGI: Forms RADIO BUTTONS
Message-Id: <Pine.GSO.3.96.970814100337.8293N-100000@julie.teleport.com>
On Thu, 14 Aug 1997, Shaun O'Shea wrote:
> But I want to know how to read the state of the radio buttons.
Use CGI.pm, which you can get from CPAN.
http://www.perl.com/CPAN/
Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 14 Aug 1997 16:30:51 GMT
From: tfletche@pcocd2.intel.com (Terry Michael Fletcher - PCD ~)
Subject: Re: comparing for a range of number - easiest way to do it?
Message-Id: <5svbrr$9i2$2@news.fm.intel.com>
Ronald Fischer (rovf@earthling.net) so eloquently and verbosely pontificated:
> does someone know an easier way to write
> die "foo" if ($x <= $a or $x >= $b);
> provided that
> $a <= $b
> and $a and $b are integers,
> and $b not very much greater as $a (i.e. that the usage of $a..$b
> would be practical)?
> I.e. I am looking for the simplest way to check if $x lies in a range
> $a..$b, but as far I understood, the range operator (..) is not
> applicable here; but maybe I'm wrong. If anyone knows a good solution
> to this, please let me know.
i think the others followups gave "better" solutions, but to do what
you're suggesting with the range, how about:
for ($a .. $b) {die "foo" if $_ == $x}
well, that is pretty short, but rather than one single compare, it does
($b-$a+1) compares. you better hope that range is small!
--
"Give me ambiguity or give me something else."
______ ______ _ _
(_) | (_) | | | | |
| _ ,_ ,_ _|_ | | _ _|_ __ | | _ ,_
_ ||/ / | / | | | / | ||/ |/ | / |/ \ |/ / |
(_/ |__/ |_/ |_/ \_/|/ (_/ |__/|__/|_/\___/| |_/|__/ |_/
*+*+*+*+*+*+*+*+*+*+*+* /| *+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
\| tfletche@pcocd2.intel.com
*+*+*+*+*+ Views expressed...not INTeL's...yadda yadda yadda.... *+*+*+*+*+*
------------------------------
Date: Thu, 14 Aug 1997 11:12:56 -0400
From: Darrell Johnson <" darrell_johnson"@nmisq2.miss.nt.com>
Subject: Re: converting from hex
Message-Id: <33F32078.4DF2@nmisq2.miss.nt.com>
Scott Houck wrote:
> <snip>
> Assuming you always have a 7-character string, this would work:
>
> $hexstring = "#ffffff";
> @rgb = map {hex} $hexstring =~ /#(..)(..)(..)/;
> print "($rgb[0], $rgb[1], $rgb[2])\n";
unpack is more efficient :)
#start of code
sub tohex ($) {
my $input = shift;
#start of relevant code
@ret= map{hex} unpack "a1a2a2a2", $input;
shift @ret;
#end of relevant code
return @ret;
};
@rgb=tohex($ARGV[0]);
print "Red : @rgb[0]\n";
print "Green: @rgb[1]\n";
print "Blue : @rgb[2]\n";
#end of code
Darrell Johnson
(drop *SPAMBEGONE* to reply)
------------------------------
Date: Thu, 14 Aug 1997 11:21:56 -0600
From: ficara@acm.org (Ken Ficara)
To: ficara@acm.org
Subject: Fork error in open()
Message-Id: <871564008.13592@dejanews.com>
I have this code running using perl 5.003 under Solaris 2.4. The
intent is to execute a command once for each machine listed in
@servers on a filehandle named for the server (making it possible to
wait on each and identify errors if any occur).
foreach $server (@servers)
{
$cmd = 'rcp foo $server: foo';
open ("$server", '-|') || exec ($cmd);
}
On one out of three machines (all Solaris 2.4) that I've run this on,
this call fails with a fatal "Can't fork" error every dozen or so
tries (ie, it works several times, then fails).
1. Can I catch this error short of exec'ing the open? Will that work?
Is there a performance penalty?
2. Can I get any further diagnostics out of perl, like what the error
return was?
3. My manpage lists only two error returns for fork(2): EAGAIN, which
perl is supposed to catch and handle in an implicit fork such as this
one (according to Camel II's entry on fork()) and ENOMEM, no swap
space. Are there other reasons fork() is likely to fail fatally?
thanks!
Ken
(If you reply via email pls don't change the subject line; I'll post
a summary if I get replies privately).
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: 14 Aug 1997 16:05:00 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: incredibly simple question
Message-Id: <5svabc$1mb@news-central.tiac.net>
In article <pviton.417.000B9699@magnus.acs.ohio-state.edu>,
Philip A. Viton <pviton@magnus.acs.ohio-state.edu> wrote:
>I'm embarassed to ask this, but I've been working with it for an hour, and
>can't see what's wrong. The fragment below is designed to say one thing if
>you type Y or y and another if you type anything else. The anything-else
>branch doesn't seem to get taken no matter what you type.
>
>print STDERR "\nPlease answer Y or N: ";
>$resp=<STDIN>;
>if ($resp = ~ /^[yY]+/)
> { print STDERR "Your response was Y\n" }
> else
> {print STDERR "Your response wasn't Y\n" }
There's a space between = and ~ it's =~ You might want to say
chomp ($resp = <STDIN>);
if (lc $resp qe 'y') {
# that's Y or y
}
else {
# it's not
}
note that /^y+/i will allow them to enter anything beginning with a y and
succeed.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: 14 Aug 1997 16:10:57 GMT
From: sohara@mardil.elsevier.nl (Steve O'Hara Smith)
Subject: Re: incredibly simple question
Message-Id: <5svamh$oe6$1@ns.elsevier.nl>
: if ($resp = ~ /^[yY]+/)
You don't want a space between = and ~.
------------------------------
Date: 14 Aug 1997 16:35:34 GMT
From: chimenti@vacuum.stl.ibm.com (Dick Chimenti)
Subject: Re: incredibly simple question
Message-Id: <5svc4m$nt0$1@sjnews.sanjose.ibm.com>
In article <pviton.417.000B9699@magnus.acs.ohio-state.edu>, pviton@magnus.acs.ohio-state.edu (Philip A. Viton) writes:
|> I'm embarassed to ask this, but I've been working with it for an hour, and
|> can't see what's wrong. The fragment below is designed to say one thing if
|> you type Y or y and another if you type anything else. The anything-else
|> branch doesn't seem to get taken no matter what you type.
|>
|> print STDERR "\nPlease answer Y or N: ";
|> $resp=<STDIN>;
|> if ($resp = ~ /^[yY]+/)
if ($resp =~ /^[yY]+/)
No space there....
|> { print STDERR "Your response was Y\n" }
|> else
|> {print STDERR "Your response wasn't Y\n" }
|>
|>
|>
|> Can ayone tell me what I'm doing wrong? THANKS!
|>
|>
|>
|> Philip A. Viton
|> ------------------
|> City Planning, Ohio State University
|> pviton@magnus.acs.ohio-state.edu
|>
--
Dick Chimenti chimenti@us.ibm.com
------------------------------
Date: Thu, 14 Aug 1997 10:00:33 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Ronald Fischer <rovf@earthling.net>
Subject: Re: Interaction between \Q and variable interpolation - please explain!
Message-Id: <Pine.GSO.3.96.970814095525.8293M-100000@julie.teleport.com>
On 13 Aug 1997, Ronald Fischer wrote:
> I am faced with the following problem: Given that
> $s='var = $abc';
> , how to write a statement that substitutes in $s the first occurence
> of $abc by REPL?
If you want to replace the literal string '$abc', then you might want
this.
s/\$abc/REPL/;
If you want the contents of $abc, taken as a regular expression, then you
might want this. (Note that the regexp must be well-formed.)
s/$abc/REPL/;
If you want the contents of $abc, taken as a string, then you might want
this.
s/\Q$abc/REPL/;
> I am surprised that \Q does not work as expected.
It works as expected, but maybe you need to fix your expectations. :-)
> Now it happens that
> quotemeta '$abc'
> returns
> '\$abc'
> which is exactly what I wanted, so I would like to know why
> s(\Q$abc)(...)
> does NOT work like
> s(\$abc)(...)
Because regular expressions are double-quote interpolated. In other words,
that works not like your quotemeta above, but like this one. (Even though
the double quotes may be omitted in this case.)
quotemeta "$abc"
Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Thu, 14 Aug 1997 15:41:14 GMT
From: gerlach@netcom.com (Matthew H. Gerlach)
Subject: Re: Need help accessing tty modem devices within perl!!!
Message-Id: <gerlachEEwu8q.wM@netcom.com>
In article <01bca860$f4fbca00$6dab9cce@Pnreit00> "Nick Reitman" <nreit00@mail.gpbx.net> writes:
>Is there anyway to use the open command to open a connection to a modem. I
>need to write a program that send some characters to the modem like
I do a ton of perl based serial IO under SunOS and SCO. After battling
ioctl(), I have come to the conclusion that the easiest way to do it
is by using Comm.pl's expect interaction with a termianl program like
ckermit from columbia.edu, tip, or cu.
Good Luck,
Matthew
------------------------------
Date: Thu, 14 Aug 1997 09:53:03 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Sami Sandqvist <sami@d246a.mtalo.ton.tut.fi>
Subject: Re: Need help!
Message-Id: <Pine.GSO.3.96.970814095157.8293K-100000@julie.teleport.com>
On 13 Aug 1997, Sami Sandqvist wrote:
> Have you considered that the users should only be able to read their
> own mailboxes? In that case, check out $ENV{MAIL} and $ENV{LOGNAME}
I don't think that the information found in environment variables is
generally reliable for user authentication! :-)
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 14 Aug 1997 15:46:04 GMT
From: emv@umich.edu (Ed Vielmetti)
Subject: Re: New User Question on FTP
Message-Id: <5sv97s$1qa$1@hawk.branch.com>
Edward Bidinotto (edbid@cobe.com) wrote:
: I am new to perl and trying to do the following:
: If (some condition)
use Net::FTP;
$ftp = Net::FTP->new("some.host.name");
$ftp->login("anonymous","me@here.there");
$ftp->cwd("/pub");
$ftp->get("that.file");
$ftp->quit;
: I can't find any examples of this in my learning perl in 21 days book
: so I guess I'm screwed until someone answers.
There's more than one way to learn Perl. In particular
you should be able to get your hands on the Camel book
when some other book doesn't give the answer. In this
case the Camel book didn't have the answer, so the next
instinct might be to use the 'perldoc' command on your
system to hunt for stuff.
Ed
Edward Vielmetti
emv@umich.edu
------------------------------
Date: Thu, 14 Aug 1997 12:47:29 -0400
From: Paul S R Chisholm <psrc@corp.airmedia.com>
To: "Syam P. Aribindi" <aribindi@cig.mot.com>
Subject: Re: NO-DELAY READ ON FIFO
Message-Id: <33F336A1.60E6@corp.airmedia.com>
Syam P. Aribindi wrote:
> Is there any way we can do nodelay read ... on sockets
> or on fifos.
On Unix and Unix-like systems, you can do something like:
use Fcntl;
# ...
fcntl(FD, O_NDELAY, 1) # ... add you own error checking
You can use this to poll various input sources, and read from them
without blocking.
Better would be to use the four argument version of select to tell when
your various input sources have data ready, then read from the source(s)
that have data. This will work with sockets for all systems that support
sockets, and for FIFOs on Unix and Unix-like systems. (I don't know if
it will work on MS Windows FIFOs.)
--
Paul S. R. Chisholm, AirMedia, Inc. (formerly Ex Machina)
mailto:psrc@corp.airmedia.com http://corp.airmedia.com/~psrc
I'm not speaking for the company, I'm just speaking my mind
------------------------------
Date: Thu, 14 Aug 1997 16:01:26 GMT
From: stuart@becool.cdac.com (Stuart Poulin)
Subject: Overriding Functions in Modules, i.e. File::Find lstat
Message-Id: <1997Aug14.160126.16692@ole.cdac.com>
How do I go about overriding a function in a module?
For example: I want File::Find to use 'stat' instead of 'lstat'
#!/usr/local/bin/perl
#
package File::Find;
sub File::Find::lstat {
print "Statting @_";
stat(@_);
}
use subs qw(lstat);
package main;
use File::Find;
find(\&wanted, '.');
sub wanted {
print "$_\n";
}
__END__
Thanks,
Stuart
--
-------------------
Stuart Poulin
stuart@cdac.com
------------------------------
Date: Thu, 14 Aug 1997 10:14:42 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Laurent Bailleux <laurent@syntem.eerie.fr>
Subject: Re: Perl and HTML
Message-Id: <Pine.GSO.3.96.970814101426.8293R-100000@julie.teleport.com>
On Thu, 14 Aug 1997, Laurent Bailleux wrote:
> My script is "OK" in a shell, but I am not able to
> make it run in my browser.
When you're having trouble with a CGI program in Perl, you should first
look at the please-don't-be-offended-by-the-name Idiot's Guide to
solving such problems. It's available on the perl.com web pages. Hope
this helps!
http://www.perl.com/perl/
http://www.perl.com/perl/faq/
http://www.perl.com/perl/faq/idiots-guide.html
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 14 Aug 1997 11:15:46 -0500
From: dougmc@comco.com (Doug McLaren)
Subject: Re: perl output destroys hard drive ?
Message-Id: <5svavi$ddv@godzilla.comco.com>
Keywords: linux hardware disk corruption
In article <thaddeus-ya023180001408971055280001@news.mdc.net>,
Thaddeus Wakefield Batt <thaddeus@activework.com> wrote:
| greetings, i'm hoping somenone can shed some light on the following behavior:
|
| running perl 5.002 under RedHat Biltmore 4.2 on a 166 MHz P-Pro w/ 128 MB
| RAM (kernel is only using 64 MB)
|
| i have a script that looks to a very large raw file for it's source and
| from that file it parses out approximately 100,000 separate files and puts
..
| however, a *few* files show up with very bizare permissions such as:
|
| ?--x--Sr-T 10 sync games 655380 Jan 1970 296601.tag
| br-xr-s--t 5 root root 30658 103, 97 Oct 8 2031 296701.tag
| drwxr-xr-x 2 prodmgr users 15360 Aug 13 14:18 295636.tag
|
| these files cannot be removed by root and when fsck is run it reports bad
| superblocks on the drive. the only way (i've found) to use the drive again
| is to manually mount it, rescue what data i can, then run mkfs.ext2
| /dev/hdb1 (i am using a 3 gig drive with only one partition for the data).
Perl could not be doing this. This is an OS or hardware problem.
It could be a linux bug, but that's unlikely (unless it's in some
hardware driver, but hda is IDE, and the IDE code should be pretty
good.) My guess would be that it's a hard drive problem, or it could
be with the cpu, memory, cache, etc. Did you adjust any hard drive
parameters with `hdparm' ?
Personally, to narrow down problems like this, I run the following
script under /usr/src/linux for a few days. Things like bad hard
drives and bad memory will cause it bomb out at random places. Run it
for a few days, and if it doesn't bomb, you're probably doing ok.
--- cut here ---
#!/bin/sh
# dougmc@frenzy.com
#
# compile your linux kernel, over and over, in an attempt to find
# hardware problems.
gettime () {
now=`perl -e "print time"`
}
check () {
error=$?
if [ $error -ne 0 ]; then
echo "Error code $error at `date`, iteraton $iteration. Aborting."
exit 1
fi
}
iteration=0
while : ; do
iteration=`expr $iteration + 1`
sync
echo "Starting compile $iteration at `date` ..."
make clean
check
gettime
start=$now
time make zImage
check
echo "Completing compile $iteration at `date`."
gettime
stop=$now
took=`expr $stop - $start`
echo "Compilation took $took s."
echo "---"
echo ""
sleep 5
done
--- cut here ---
In any event, I hope you're not putting 100k files into one directory
at one time, not even temporarily ... that's a great way to s l o w
things down incredibly. Hopefully ext3 will have btrees or something
similar for directory access :)
This isn't a perl problem, so followups are redirected to
comp.os.linux.hardware.
--
Doug McLaren, dougmc@comco.com
Unsolicited email of a commercial or advertising nature is not welcomed.
<http://spam.abuse.net/spam/> Because The Only GOOD Spammer is a DEAD Spammer
------------------------------
Date: Thu, 14 Aug 1997 10:19:52 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Thaddeus Wakefield Batt <thaddeus@activework.com>
Subject: Re: perl output destroys hard drive ?
Message-Id: <Pine.GSO.3.96.970814101642.8293S-100000@julie.teleport.com>
On Thu, 14 Aug 1997, Thaddeus Wakefield Batt wrote:
> however, a *few* files show up with very bizare permissions such as:
>
> ?--x--Sr-T 10 sync games 655380 Jan 1970 296601.tag
> br-xr-s--t 5 root root 30658 103, 97 Oct 8 2031 296701.tag
> drwxr-xr-x 2 prodmgr users 15360 Aug 13 14:18 295636.tag
Is your script running as root? If not, then this is a sign of a serious
derangement in your system. If it is running as root, it still might mean
that your OS has taken some bad acid, and should be hospitalized at once.
You may want to ask about this in a Linux-specific newsgroup; someone
there may have heard of this problem. But I'd think you'd want to backup
early, backup often, and prepare to re-install the whole ball of wax ASAP.
Good luck!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Thu, 14 Aug 1997 15:57:26 +0100
From: b.wilkinson@pindar.co.uk (Bob Wilkinson)
Subject: Re: Puting pattern in a variable
Message-Id: <b.wilkinson-1408971557260001@ip57-york.pindar.co.uk>
In article <33F0BE62.41C67EA6@teleglobe.ca>, Vladimir Parkhaev
<vlad@teleglobe.ca> wrote:
> Hi everybody,
> I've created an array of patterns. And I need
> to match a variable to find out if it matches
> at least one of them.
>
> Something like this:
>
> foreach $regex (@List) {
> if ($_ =~ $regex) {
> print "OK";
> }
> else {
> print "No match";
> }
>
> }
>
> I've tried about everything, including eval.
> Nothing seem to work. Has anybody tried this before?
Hello,
Try something like
my $regex = join("|",@List);
if (/$regex/) {
print "OK\n";
} else {
print "No match\n";
}
Bob
--
.sig file on holiday
------------------------------
Date: Thu, 14 Aug 1997 10:07:06 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Kevin Chin <kchin@nva.lmco.com>
Subject: Re: Setting Groupid
Message-Id: <Pine.GSO.3.96.970814100516.8293O-100000@julie.teleport.com>
On Mon, 11 Aug 1997, Kevin Chin wrote:
> About a week ago, I posted a question to this group about setting the
> groupid within Solaris Perl. I got some responses. Thank you.
> However, I took the advice, recompiled perl to implement setrgid() and
> it still does not work.
>
> I was wondering if anyone has been successful in setting the groupid on
> a Solaris 2.5 system using perl. Please let me know. Thanks.
Can you make an experimental C program which uses setrgid() to do what you
want? If a C program can do it and Perl cannot, then there's either a bug
in Perl or a problem with the way you've compiled it. But if it can't be
done from C, then it can't be done from Perl. Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Thu, 14 Aug 1997 13:00:37 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Simple question on s/// operator in expressions
Message-Id: <comdog-ya02408000R1408971300370001@alice.walrus.com>
In article <33F31FB0.FC124FC@oberbrunner.com>, Gary Oberbrunner <garyo@oberbrunner.com> wrote:
>I often want to do a substitution on a string and use the result 'in-line',
>without having to create a new variable just to hold the result (or modify the
>original string). The only way I have found is to substitute into another
>variable with this hack:
>
> $foo = "my string\n";
> $tempfoo = $foo;
> $tempfoo =~ s/my/my new/;
> print $newfoo;
>
>when all I really want is something like this:
>
> $foo = "my string\n";
> print s/my/my new/ ($foo); # Syntax error, s/// is not a unary operator.
does using $_ solve your problem? this avoids creating a variable to hold
the result, although you lose the modification whenever something else
overwrites $_.
#!/usr/bin/perl
$foo = "my string\n";
$_ = $foo;
s/my/my new/;
print;
__END__
--
brian d foy <comdog@computerdog.com>
------------------------------
Date: Thu, 14 Aug 1997 10:27:14 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Gary Oberbrunner <garyo@oberbrunner.com>
Subject: Re: Simple question on s/// operator in expressions
Message-Id: <Pine.GSO.3.96.970814102505.8293U-100000@julie.teleport.com>
On Thu, 14 Aug 1997, Gary Oberbrunner wrote:
> I often want to do a substitution on a string and use the result
> 'in-line', without having to create a new variable just to hold the
> result (or modify the original string).
The s/// operator can only work on a variable. But you don't have to
create a new global. You can make a my() variable in a limited scope.
$foo = "my string\n";
{ # Naked block creates a scope.
(my $temp = $foo) =~ s/my/my new/;
print $temp;
}
Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Thu, 14 Aug 1997 11:29:26 -0500
From: Dave Lilly <lilly@fedex.com>
Subject: Re: sorting...
Message-Id: <33F33266.167E@fedex.com>
<snip>
> > foreach (sort values %MAIN_CHOICES){
> > print "$MAIN_CHOICES{$_} has a value of $_\n <br>";
> > }
> >
> > That sorts alphabetically by values.
>
> Quizically, though, this yields:
>
> has a value of The value for key 0003, silly!
> has a value of This is the value for key 0001
> has a value of This is the value for key 0002
>
> What did I miss? My keys are 0001,0002,etc.. Should the key have been output at
> the beginning of each line in the second snip? Thanks!!
>
Well, in that foreach loop, you're looping throught the values in
%MAIN_CHOICES. That's fine, but what you are not taking into account is
that $MAIN_CHOICES{$_} is undefined...you're trying to access
$MAIN_CHOICES{$value} instead of $MAIN_CHOICES{$key}. It doesn't work
that way...may I suggest the following:
#!/bin/perl
$MAIN_CHOICES{"0001"} = "This is the value for key 0001";
$MAIN_CHOICES{"0002"} = "This is the value for key 0002";
$MAIN_CHOICES{"0003"} = "The value for key 0003, silly!";
sub alpha_val {$MAIN_CHOICES{$a} cmp $MAIN_CHOICES{$b};}
foreach (sort alpha_val keys %MAIN_CHOICES) {
print "$_ has a value of $MAIN_CHOICES{$_}\n";
}
...this produces:
0003 has a value of The value for key 0003, silly!
0001 has a value of This is the value for key 0001
0002 has a value of This is the value for key 0002
which I think is what you want...
Hope this helps!
-dave
------------------------------
Date: Thu, 14 Aug 1997 10:08:30 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Anagrams of the Word <jefpin@bergen.org>
Subject: Re: sorting...
Message-Id: <Pine.GSO.3.96.970814100742.8293P-100000@julie.teleport.com>
On Thu, 14 Aug 1997, Anagrams of the Word wrote:
> foreach (sort values %MAIN_CHOICES){
> print "$MAIN_CHOICES{$_} has a value of $_\n <br>";
> }
>
> That sorts alphabetically by values.
Yes, it does. But what it prints out is completely bogus.
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 14 Aug 1997 15:21:24 GMT
From: stampes@xilinx.com (Jeff Stampes)
Subject: Uninitialized Value? Really?
Message-Id: <5sv7pk$9q8$1@neocad.com>
I always use -w....
I even use strict a lot...
I thought I had the hang of ensuring good safe data under these
rules, but 5.004_01 has me confused.
In a script with a -w and no use strict, I have the code in one
of my subroutines (Yes, I know getopt could be used for this, I'm
just not....) :
sub parse_args
{
my (@args) = (@_);
my $pkg = '';
my $ver = '';
my $rid = '';
my @platforms = ();
my %platforms = (
sun => 1,
sol => 1,
nt => 1,
hp => 1,
rs6000 => 1, );
foreach (@args)
{
if (/-h/) {&usage}
if (defined $platforms{$_}) {push @platforms, $_}
if (/^-r/) {($rid = $_) =~ s/^-r(.+)$/$1/}
}
$pkg = $args[-2] || $pkg;
$ver = $args[-1] || $ver;
&usage if (($pkg eq '' ||
$ver eq '' ) &&
($rid eq ''));
if (@platforms == ()) {@platforms = keys %platforms} ## Line 317
return(\@platforms,$pkg,$ver,$rid);
}
When I run this, I get:
Use of uninitialized value at patch_build line 317.
Hmmm...Sure looks like I initialized the only two values mentioned
in like 317. Anyone have any idea what it's bitching about?
Cheers,
Jeff
--
Jeff Stampes -- Xilinx, Inc. -- Boulder, CO -- jeff.stampes@xilinx.com
------------------------------
Date: Thu, 14 Aug 1997 10:24:22 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: stefano bonacina <stefano.bonacina@st.com>
Subject: Re: Variable substitution into a regexp
Message-Id: <Pine.GSO.3.96.970814102153.8293T-100000@julie.teleport.com>
On Wed, 13 Aug 1997, stefano bonacina wrote:
> $rec =~ s|<$field>(.*?)</$field>||;
> Actually the regexp doesn't work. How can I escape the $s?
If you want to search and replace actual $ signs, use a backslash. If you
want to quote metacharacters in the variable $field, use \Q . If you want
to use the contents of $field as (parts of) regular expressions, what you
have should work. If you want something else, I don't know what it could
be. :-)
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 14 Aug 1997 15:49:19 GMT
From: "Gary Ng" <garyng@ibm.net>
Subject: Re: version of Perl5 for NT4
Message-Id: <01bca8c9$aca1a9a0$c11952ca@dkkong>
Danny Aldham <danny@lennon.postino.com> wrote in article
<5su5ld$2nv$1@lennon.postino.com>...
> Just run the executable. If you get braver you can go to
> www.cygnus.com and download their gcc dev kit. Then with some
> patches & a bit of hacking, it is possible to roll your own
> perl5.004_1 .
>
A correction. perl5.004_01 and up build out of the box
on NT using VC++ or BC 5.02. No hacking and patches needed.
Gary
------------------------------
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 867
*************************************