[18350] in Perl-Users-Digest
Perl-Users Digest, Issue: 518 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Mar 18 03:06:02 2001
Date: Sun, 18 Mar 2001 00:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <984902709-v10-i518@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 18 Mar 2001 Volume: 10 Number: 518
Today's topics:
${_}name -> compile error? (Jim Kroger)
Re: ${_}name -> compile error? (Jim Kroger)
Re: ${_}name -> compile error? (Logan Shaw)
Re: ${_}name -> compile error? <joe+usenet@sunstarsys.com>
Re: ${_}name -> compile error? (Eric Bohlman)
Re: ${_}name -> compile error? <ben.sugars@home.com>
Re: ${_}name -> compile error? <ben.sugars@home.com>
Re: ${_}name -> compile error? <uri@sysarch.com>
Re: -w and use strict; <uri@sysarch.com>
5.6.0 install trouble <jason@matchingmoms.com>
Re: help on getting a sorted list of total number of oc (Martien Verbruggen)
Re: HTTP Client Question <bactitech@hortonsbay.com>
MicroWeb Installation of lib-net <jtjohnston@courrier.usherb.ca>
Perl for Windows <jtjohnston@courrier.usherb.ca>
Re: Print to file (Eric Bohlman)
Re: Print to file <nospam@nospam.net>
Re: Simple Email @ Parsing Solution? (Eric Bohlman)
Re: Tk based alarm clock (Victor Wagner)
Why "Invalid conversion"? <nlp0421@gz.cngb.com>
Re: Why "Invalid conversion"? <kevin@vaildc.net>
Re: Why "Invalid conversion"? (Garry Williams)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 17 Mar 2001 23:03:03 -0500
From: minorseventhSPAMBLOCK@earthlink.net (Jim Kroger)
Subject: ${_}name -> compile error?
Message-Id: <minorseventhSPAMBLOCK-1703012303030001@tritone.csbmb.princeton.edu>
Hi. I have the following code:
foreach $_ ($subjects) {
s/\s+//;
chomp($tmp = `grep $_ $dffile | wc`);
@tmp = split /\s+/, $tmp;
${_}lines = $tmp[1]; <<<<<<<<<<<< error
}
I need to put the number of lines in the subject's data file into a variable,
for example, the number of lines in anna's file into $annalines.
The debugger complains:
Bareword found where operator expected at new line 45, near "${_}lines"
I know I should use -w and strict, and I will clean this up, but am
somewhat desperately trying to get it to run tonight.
Thanks very much,
Jim
------------------------------
Date: Sat, 17 Mar 2001 23:05:12 -0500
From: minorseventhSPAMBLOCK@earthlink.net (Jim Kroger)
Subject: Re: ${_}name -> compile error?
Message-Id: <minorseventhSPAMBLOCK-1703012305120001@tritone.csbmb.princeton.edu>
> foreach $_ ($subjects) {
> s/\s+//;
> chomp($tmp = `grep $_ $dffile | wc`);
> @tmp = split /\s+/, $tmp;
> ${_}lines = $tmp[1]; <<<<<<<<<<<< error
> }
>
Sorry, that should read:
foreach $_ (@subjects) {
with the @ instead of the $.
Thanks
Jim
------------------------------
Date: 17 Mar 2001 23:23:59 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: ${_}name -> compile error?
Message-Id: <991gpf$5ml$1@boomer.cs.utexas.edu>
In article <minorseventhSPAMBLOCK-1703012303030001@tritone.csbmb.princeton.edu>,
Jim Kroger <minorseventhSPAMBLOCK@earthlink.net> wrote:
>Hi. I have the following code:
>
>foreach $_ ($subjects) {
> s/\s+//;
> chomp($tmp = `grep $_ $dffile | wc`);
> @tmp = split /\s+/, $tmp;
> ${_}lines = $tmp[1]; <<<<<<<<<<<< error
>}
>
>I need to put the number of lines in the subject's data file into a variable,
>for example, the number of lines in anna's file into $annalines.
>
>The debugger complains:
>Bareword found where operator expected at new line 45, near "${_}lines"
Of course that's a compile error. ${_} is a perfectly good variable
name. After perl sees that, it knows it's done with that variable, and
it goes on to something else. What it sees next is "lines". What Perl
sees is much the same as if you had done this:
$_ lines = $tmp[1];
You can see why the interpreter would get confused.
Anyway, you're doing this the hard way. Associative arrays are meant
for exactly this kind of thing, so you should use them.
You could change this:
${_}lines = $tmp[1];
to this:
$lines{$_} = $tmp[1];
Also, your script is really slow, because it's running an external
process (grep) over and over on the same file, when you could read it
into memory just once. (And I don't even want to think about what will
happen if @subjects contains a line like "; rm -rf / ".)
You could do it all in Perl instead:
open (DFFILE, $dffile) or die "can't open $dffile ($!)\n";
@dffile = <DFFILE>;
close DFFILE;
foreach my $subject (@subjects)
{
$subject =~ s/\+s//;
$lines{$subject} = grep (/$subject/, @dffile);
}
Actually, it might be better not to use a regular expression if you
don't want the extra features regular expressions give you. So,
you might do this instead:
open (DFFILE, $dffile) or die "can't open $dffile ($!)\n";
@dffile = <DFFILE>;
close DFFILE;
foreach my $subject (@subjects)
{
$subject =~ s/\+s//;
$lines{$_} = grep (index ($_, $subject) >= 0, @dffile);
}
Hope that helps.
- Logan
--
whose? my your his her our their _its_
who's? I'm you're he's she's we're they're _it's_
------------------------------
Date: 18 Mar 2001 00:26:30 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: ${_}name -> compile error?
Message-Id: <m3vgp7r6k9.fsf@mumonkan.sunstarsys.com>
minorseventhSPAMBLOCK@earthlink.net (Jim Kroger) writes:
[reworked a little :]
> foreach $_ (@subjects) {
> > s/\s+//;
^^^^^^^
This will remove the first sequence of space characters that appear
in each element of @subjects. In so doing, it modifies the elements of
@subjects:
% perl -le '@_=("A A ", "B"); foreach $_ (@_) { s/\s+// } print @_;'
AA B
%
Presumably this is OK with you, right?
> > chomp($tmp = `grep $_ $dffile | wc`);
> > @tmp = split /\s+/, $tmp;
> > ${_}lines = $tmp[1]; <<<<<<<<<<<< error
^^^^^^^^^
You are looking for a hash- so just reorder the brackets:
$lines{$_} = $tmp[1]; # puts *second* item of @tmp in %lines
# using $_ as the key
You don't want to use variable names as variables themselves- that
amounts to using symrefs, which is almost always the wrong approach.
Just use a hash instead, and when you have the time look at
http://perl.plover.com/varvarname.html
It's in three parts, so be sure to read them all.
btw: the second item returned by wc is the number of words, not lines.
You might want to either change that [1] to a [0], use wc -l, or just
use grep -c. Here's two more approaches:
1) using a hash slice with map:
s/\s+//g for @subjects;
chomp( @lines{@subjects} = map {`grep -c $_ $dffile`} @subjects );
2) write the loop with a modifier:
s/\s+//, chomp( $lines{$_} = `grep -c $_ $dffile` ) for (@subjects);
HTH
--
Joe Schaefer "Buy land. They've stopped making it."
--Mark Twain
------------------------------
Date: 18 Mar 2001 05:40:27 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: ${_}name -> compile error?
Message-Id: <991hob$re7$1@bob.news.rcn.net>
Jim Kroger <minorseventhSPAMBLOCK@earthlink.net> wrote:
> Hi. I have the following code:
> foreach $_ ($subjects) {
Which you noted should have been "@subjects"
> s/\s+//;
> chomp($tmp = `grep $_ $dffile | wc`);
> @tmp = split /\s+/, $tmp;
> ${_}lines = $tmp[1]; <<<<<<<<<<<< error
> }
> I need to put the number of lines in the subject's data file into a variable,
> for example, the number of lines in anna's file into $annalines.
No, you don't need to do that. You need to put the number of lines into a
hash keyed by the subject's name:
$lines{$_} = $tmp[1];
> The debugger complains:
> Bareword found where operator expected at new line 45, near "${_}lines"
That's because the statement begins with "$_" (the brackets just serve to
indicate that the "_" is the last character of the identifier), which is a
variable name, and then has an unquoted string which, since you don't have
strictures enabled, is treated as the literal string "lines." The problem
is that there's no place in Perl's grammar where a statement can begin
with a variable name followed immediately by a literal string. You're
trying to construct what's called a symbolic reference (which is almost
never a good idea even if you do it correctly) but you're doing it wrong.
> I know I should use -w and strict, and I will clean this up, but am
> somewhat desperately trying to get it to run tonight.
Use the hash, Luke.
------------------------------
Date: Sun, 18 Mar 2001 06:03:33 GMT
From: Benjamin Sugars <ben.sugars@home.com>
Subject: Re: ${_}name -> compile error?
Message-Id: <Pine.LNX.4.21.0103180100230.32066-100000@localhost.localdomain>
On Sat, 17 Mar 2001, Jim Kroger wrote:
> ${_}lines = $tmp[1]; <<<<<<<<<<<< error
Try ${"${_}lines"} = $tmp[1];
> I know I should use -w and strict, and I will clean this up, but am
> somewhat desperately trying to get it to run tonight.
Indeed.
Cheers,
-Ben
--
Benjamin Sugars <ben.sugars@home.com>
------------------------------
Date: Sun, 18 Mar 2001 06:09:05 GMT
From: Benjamin Sugars <ben.sugars@home.com>
Subject: Re: ${_}name -> compile error?
Message-Id: <Pine.LNX.4.21.0103180107570.32066-100000@localhost.localdomain>
On Sun, 18 Mar 2001, I, Benjamin Sugars, wrote:
> On Sat, 17 Mar 2001, Jim Kroger wrote:
>
> > ${_}lines = $tmp[1]; <<<<<<<<<<<< error
>
> Try ${"${_}lines"} = $tmp[1];
I should add, this is assuming you actually *mean* to use symbolic
refs. Why not use a hash?
Cheers,
-Ben
--
Benjamin Sugars <ben.sugars@home.com>
------------------------------
Date: Sun, 18 Mar 2001 06:28:23 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: ${_}name -> compile error?
Message-Id: <x77l1n616f.fsf@home.sysarch.com>
>>>>> "BS" == Benjamin Sugars <ben.sugars@home.com> writes:
BS> On Sat, 17 Mar 2001, Jim Kroger wrote:
>> ${_}lines = $tmp[1]; <<<<<<<<<<<< error
BS> Try ${"${_}lines"} = $tmp[1];
NO! don't try that. that is a symref and is very wrong and evil. the
other answers are correct, use a hash.
if you think that is a good answer, fix your neural pathways and remove
symrefs from yyour brain.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Sun, 18 Mar 2001 03:18:44 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: -w and use strict;
Message-Id: <x7ae6j69yj.fsf@home.sysarch.com>
>>>>> "G" == Godzilla! <godzilla@stomp.stomp.tokyo> writes:
G> Uri Guttman wrote:
>> show me anywhere in the docs that calls -w a pragma.
>> quote it if you can. please!!
G> Randal's excellent books, Learning Perl and Programming Perl,
G> would be a good place to begin improving your Perl Knowledge.
G> You do pretty good at Perl but still have a bit of learning.
randal is not an author of programming perl 3rd edition. learn to read
title pages. now that you mention books, quote the page numbers where
either one says -w is a pragma. the actual page number please.
and then try to find anything in the online docs that calls -w a pragma.
you have not yet properly shown any evidence that -w is a pragma. show
some. saying a book says it without pointing out which pages it is on is
not evidence. i am sure the authors of those books would be interested
in hearing about this alleged mistake. but since larry wall was one of
the authors of PP and defined how the term pragma is used (standard
modules that affect compile time behavior) i would think he would know
that -w is not a pragma. now, 5.6 has use warnings which IS a pragma but
that is not -w which is all 5.5 and earlier versions have.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Sat, 17 Mar 2001 20:15:00 -0700
From: <jason@matchingmoms.com>
Subject: 5.6.0 install trouble
Message-Id: <NKVs6.3595$Ym5.624372@news.uswest.net>
I'm getting an error when I try to 'make'. Any help would be appreciated!
Jason
friejas ~/perl-5.6.0>./myconfig
Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
Platform:
osname=linux, osvers=2.2.17, archname=i686-linux
uname='linux jsf_host 2.2.17 #1 sun jun 25 09:24:41 est 2000 i686
unknown '
config_args='-de'
hint=previous, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
useperlio=undef d_sfio=undef uselargefiles=define
use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef
Compiler:
cc='cc', optimize='-O2', gccversion=2.95.2 20000220 (Debian GNU/Linux)
cppflags='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_F
ILE_OFFSET_BITS=64'
ccflags
='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFS
ET_BITS=64'
stdchar='char', d_stdstdio=define, usevfork=false
intsize=4, longsize=4, ptrsize=4, doublesize=8
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=4, usemymalloc=n, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -lndbm -ldb -ldl -lm -lc -lposix -lcrypt
libc=/lib/libc-2.2.2.so, so=so, useshrplib=false, libperl=libperl.a
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
root /home/friejas/perl-5.6.0>make
`sh cflags libperl.a miniperlmain.o` miniperlmain.c
CCCMD =
cc -DPERL_CORE -c -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOU
RCE -D_FILE_OFFSET_BITS=64 -O2
. . . OTHER OUTPUT OMITTED HERE . . .
Writing Makefile for DynaLoader
make[1]: Entering directory `/home/friejas/perl-5.6.0/ext/DynaLoader'
make[1]: Leaving directory `/home/friejas/perl-5.6.0/ext/DynaLoader'
make[1]: Entering directory `/home/friejas/perl-5.6.0/ext/DynaLoader'
../../miniperl -I../../lib -I../../lib -I../../lib -I../../lib
DynaLoader_pm.PL DynaLoader.pm
../../miniperl -I../../lib -I../../lib -I../../lib -I../../lib
XSLoader_pm.PL XSLoader.pm
Skip ../../lib/XSLoader.pm (unchanged)
Skip ../../lib/DynaLoader.pm (unchanged)
make[1]: Leaving directory `/home/friejas/perl-5.6.0/ext/DynaLoader'
cc -L/usr/local/lib -rdynamic -o perl perlmain.o
lib/auto/DynaLoader/DynaLoader.a libperl.a `cat
ext.libs` -lnsl -lndbm -ldb -ldl
cc: lib/auto/DynaLoader/DynaLoader.a: No such file or directory
make: *** [perl] Error 1
root /home/friejas/perl-5.6.0>make test
AutoSplitting perl library
./miniperl -Ilib -e 'use AutoSplit; \
autosplit_lib_modules(@ARGV)' lib/*.pm lib/*/*.pm
Making DynaLoader (static)
make[1]: Entering directory `/home/friejas/perl-5.6.0/ext/DynaLoader'
make[1]: Leaving directory `/home/friejas/perl-5.6.0/ext/DynaLoader'
make[1]: Entering directory `/home/friejas/perl-5.6.0/ext/DynaLoader'
make[1]: Leaving directory `/home/friejas/perl-5.6.0/ext/DynaLoader'
cc -L/usr/local/lib -rdynamic -o perl perlmain.o
lib/auto/DynaLoader/DynaLoader.a libperl.a `cat
ext.libs` -lnsl -lndbm -ldb -ldl
cc: lib/auto/DynaLoader/DynaLoader.a: No such file or directory
make: *** [perl] Error 1
------------------------------
Date: Sun, 18 Mar 2001 14:03:12 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: help on getting a sorted list of total number of occurences of the same value of a field in a file
Message-Id: <slrn9b89bg.i70.mgjv@martien.heliotrope.home>
On Sun, 18 Mar 2001 02:04:19 GMT,
sam <sammy@bigpond.net.au> wrote:
> Appreciate advise on following:
>
> I have a unix file containing ~ 100k lines consisting of 1st field number
> string 2nd number string several other fields also.
>
> I want to find the total number of times each first field is the same and
> get a total then sort it so I have the most occurences at either top or
> bottom of list
> for each different occurence and its total.
>
> I could write it in shell but it would be far too slow too much forking.
>
> I'm quite new to perl so I'd appreciate any explanations of syntax but use
> alot of standard unix filtering awk sed ...
We normally don't get in the habit of writing programs for people, but
this is quite elementary. You're asking for something that uses so many
fundamental things that Perl is good at, that I'll actually write it.
It'll have loads of references to documentation. Follow those. Read the
documentation. Use man, on Unix, or perldoc. I'll write it out in
longhand, so that it's easier to follow.
\begin{instruction}
#!/usr/local/bin/perl -w
use strict;
# Where we keep counts of the first field. Read perldata, and the Perl
# FAQ, section 4
my %seen;
# The file name that contains the data. I just read it from the end of
# this file. Change it to a real filename for your program. Read about
# __DATA__ in perldata and about dup-ing filehandles in perlfunc:open()
my $file = "<&DATA";
# open the file. Read the entry for open() in perlfunc, and perlopentut.
open FILE, $file or die "Couldn't open '$file': $!";
# Loop over the lines of the file. Read perlsyn and perlop
while (my $line = <FILE>)
{
# Get the 'fields', read about split() in perlfunc. Pay attention to
# the special pattern I'm using. It's described there.
my @fields = split ' ', $line;
# Update the %seen hash. Read perlop for the ++ operator.
$seen{$fields[0]}++;
}
close FILE;
# Loop over all the entries in %seen, sorted by the value. See perlsyn,
# keys() and sort() in perlfunc, and perl FAQ, section 4, question 'How
# do I sort a hash?'. Pay attention to the order of $a and $b.
foreach my $thing (sort { $seen{$b} <=> $seen{$a} } keys %seen)
{
print "$thing\t$seen{$thing}\n";
}
__DATA__
45.67.78.90 fred jones 19yrs London England
45.67.78.60 fred jones 19yrs London England
45.67.78.90 fred jones 19yrs London England
45.67.78.80 fred jones 19yrs London England
45.67.78.90 fred jones 19yrs London England
45.67.78.80 fred jones 19yrs London England
\end{instruction}
Unless this was part of a much larger program, I'd probably write
something like:
#!/usr/local/bin/perl -wl
$_{(split)[0]}++ while (<>);
print "$_\t$_{$_}" for sort { $_{$b} <=> $_{$a} } keys %_;
or even
#!/usr/local/bin/perl -wln
$_{(split)[0]}++;
END{ print "$_\t$_{$_}" for sort { $_{$b} <=> $_{$a} } keys %_ }
and call it as
$ ./whatever filename
But that wouldn't be instructive. :).
Other manual pages to read: perlvar, perlrun and strict.
Martien
--
Martien Verbruggen |
Interactive Media Division | Little girls, like butterflies, need
Commercial Dynamics Pty. Ltd. | no excuse - Lazarus Long
NSW, Australia |
------------------------------
Date: Sun, 18 Mar 2001 00:23:52 -0500
From: Dilworth <bactitech@hortonsbay.com>
Subject: Re: HTTP Client Question
Message-Id: <3ab446b3$0$14440$1dc6e903@news.corecomm.net>
Gwyn Judd wrote:
> >Anno Siegel wrote:
> >>
> >> Because it damages the thread it appears in. Posting style is
> >> *not* a matter of personal preference.
> >>
> >> [rest of somewhat tiring argumentation snipped]
> >>
> >> Anno
> >
> >Life is too short to deal with folks like you however vast your
> >knowledge and expertise.
> >
> >*plonk*
>
> Plonking Anno *and* Abigail in one thread. That takes out about %10 of
> the total volume in clpm. Do you plan on plonking any of the other
> regulars or will that suffice for one day?
Well, I find them to be mean and nasty more often than not. They're
allowed to "plonk" at will so I say they heck with them.
Bob D.
------------------------------
Date: Sat, 17 Mar 2001 21:38:59 -0500
From: jtjohnston <jtjohnston@courrier.usherb.ca>
Subject: MicroWeb Installation of lib-net
Message-Id: <3AB41FC3.44AB9A86@courrier.usherb.ca>
http://www.indigostar.com/microweb.htm is a mini-server, Windows App
sworn to be able to be run perl from a CD-Rom.
I am using http://www.indigostar.com/microweb.htm for which I am going
to attempt to install a copy of lib-net on the back of the copy of Perl
he has.
I need to use smtp.pm to send email. I had a copy of lib-net installed
in a Sambar server, but I am going to use
http://www.indigostar.com/microweb.htm to run a mini-server from a
CD-Rom.
Which copy, where, of lib-net is best? Has anyone ventured as much?
Thanks,
John
(As usual, an email post-reply would be a big help. I cannot get to the
groups that often from work.)
------------------------------
Date: Sat, 17 Mar 2001 23:25:07 -0500
From: jtjohnston <jtjohnston@courrier.usherb.ca>
Subject: Perl for Windows
Message-Id: <3AB438A2.7164CBC8@courrier.usherb.ca>
Is Activestate teh only binary compiled. I don't the most recent
compile.
What I do need is to install lib-net.
John
(An email & post would be most helpful :)
------------------------------
Date: 18 Mar 2001 05:55:10 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Print to file
Message-Id: <991iju$re7$2@bob.news.rcn.net>
len.green <len.green@ntlworld.com> wrote:
> Win32 does not support flock();
False. While the "consumer" versions (95, 98, ME) don't support it, the
"pro" versions (NT, 2000) do. It's unlikely that a production CGI program
is going to be run on one of the "consumer" systems, so the problem is
probably something else.
------------------------------
Date: Sun, 18 Mar 2001 06:07:12 GMT
From: "David Ehrens" <nospam@nospam.net>
Subject: Re: Print to file
Message-Id: <kgYs6.16755$mH4.4052706@typhoon.ne.mediaone.net>
> len.green <len.green@ntlworld.com> wrote:
> > Win32 does not support flock();
Win32 has been flocked for quite a while.
------------------------------
Date: 18 Mar 2001 05:57:47 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Simple Email @ Parsing Solution?
Message-Id: <991ior$re7$3@bob.news.rcn.net>
Dave Davis <dave.davis@ultrainteractive.com> wrote:
> I'm trying to grab an email address from a form, and paste it back into a
> sendmail message as a recipient. What's the simplest solution to handling
> the obvious problem (the @ character hangs... in the non-variable lines its
> escaped with /@ for sending).
The only time an at-sign needs escaping is when it appears inside a
double-quotish literal string in your program file. If you read in a
string from an external source, perl doesn't treat at-signs as being
special. It looks like you're trying to solve a non-problem.
------------------------------
Date: 17 Mar 2001 11:53:17 +0300
From: vitus@wagner.rinet.ru (Victor Wagner)
Subject: Re: Tk based alarm clock
Message-Id: <98v8lt$1k4$1@wagner.wagner.home>
In comp.os.linux.misc Donal K. Fellows <fellowsd@cs.man.ac.uk> wrote:
: Victor Wagner wrote:
:> By the way, it would require perl or Tcl interpreter to stay in memory
:> during all your login session, and this seems to much for just an alarm
:> clock.
: It depends on whether you already have an interpreter already present.
: The overhead for a separate interpreter within an already-running
: process is pretty small...
Considering that most of tcl and tk is part of shared library,
I would say that effect of having another tcl/tk script running
is negligible, if I already have another script running as separate
process.
So, if alarm clock app is part of some desktop goodies suite, it
probably will be Ok.
But if it is only Tk app, running on machine, it is another question.
It was precisely the point of my previous letter
--
'Course, that doesn't work when 'a' contains parentheses.
-- Larry Wall in <199710211647.JAA17957@wall.org>
------------------------------
Date: Sun, 18 Mar 2001 12:41:17 +0800
From: "J.A.W" <nlp0421@gz.cngb.com>
Subject: Why "Invalid conversion"?
Message-Id: <991efi$2987$1@news.cz.js.cn>
Why does this line cause a warning message "Invalid conversion..." but
compiles anyway?
printf OUTPUT_FILE "%4d%\n",$conf/5*100; #where $conf is a numeric
JAW
------------------------------
Date: Sat, 17 Mar 2001 23:56:13 -0500
From: Kevin Michael Vail <kevin@vaildc.net>
Subject: Re: Why "Invalid conversion"?
Message-Id: <kevin-813FB0.23555817032001@news.his.com>
In article <991efi$2987$1@news.cz.js.cn>, "J.A.W" <nlp0421@gz.cngb.com>
wrote:
> Why does this line cause a warning message "Invalid conversion..." but
> compiles anyway?
>
> printf OUTPUT_FILE "%4d%\n",$conf/5*100; #where $conf is a numeric
^^
I'd be willing to be this is it. You should probably have two % here.
--
Kevin Michael Vail | a billion stars go spinning through the night,
kevin@vaildc.net | blazing high above your head.
. . . . . . . . . | But _in_ you is the presence that
. . . . . . . . . | will be, when all the stars are dead. (Rainer Maria Rilke)
------------------------------
Date: Sun, 18 Mar 2001 05:31:55 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Why "Invalid conversion"?
Message-Id: <fLXs6.166$ez4.7729@eagle.america.net>
On Sun, 18 Mar 2001 12:41:17 +0800, J.A.W <nlp0421@gz.cngb.com> wrote:
>Why does this line cause a warning message "Invalid conversion..." but
>compiles anyway?
>
>printf OUTPUT_FILE "%4d%\n",$conf/5*100; #where $conf is a numeric
The warning message actually gives a hint:
$ perl -we '$c=34;printf "%4d%\n",$c/5*100;'
Invalid conversion in printf: "%
" at -e line 1.
680%
Did you wonder why the warning message was split over two lines? It
is quoting a part of your format string -- the "%\n" part. That's why
there's a break in the error message line. So it's complaining about
the second `%'.
I assume that you want an actual `%' on the end of the number you're
printing, yes? Perl assumes you are starting another conversion
specification.
You must double up to get a literal `%' like this: "%4d%%\n".
The Perl manual is a little challenging on this one. The printf()
section of the perlfunc manual page refers you to the sprintf()
section and it refers you to your system's sprintf(3) or printf(3)
manual page.
But right after the referral, the very first conversion specification
is:
%% a percent sign
See the perlfunc manual page.
--
Garry Williams
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 518
**************************************