[15528] in Perl-Users-Digest
Perl-Users Digest, Issue: 2938 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 3 18:15:37 2000
Date: Wed, 3 May 2000 15:15:25 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <957392125-v9-i2938@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 3 May 2000 Volume: 9 Number: 2938
Today's topics:
Re: Reading and Writing to a file (Tad McClellan)
Re: Reading and Writing to a file (Tad McClellan)
Re: Reading and Writing to a file <andrew.mcguire@walgreens.com>
Re: Reading and Writing to a file <andrew.mcguire@walgreens.com>
Re: Reading and Writing to a file <jeff@vpservices.com>
Re: Reading and Writing to a file <lr@hpl.hp.com>
Re: Reading and Writing to a file <godzilla@stomp.stomp.tokyo>
Re: Reading and Writing to a file <lr@hpl.hp.com>
Re: Reading and Writing to a file <andrew.mcguire@walgreens.com>
Re: Reading and Writing to a file <jeff@vpservices.com>
Re: Reading and Writing to a file <godzilla@stomp.stomp.tokyo>
Re: reg expressions assistance (Tad McClellan)
Re: reg expressions assistance <fortkid@bellsouth.net>
Re: Regex for not matching a particular string <lr@hpl.hp.com>
Re: Regex for not matching a particular string (Craig Berry)
Re: Regexp speed (was: Help: bol regexp in split string <occitan@esperanto.org>
Re: Regexp speed (was: Help: bol regexp in split string <uri@sysarch.com>
Re: Remove all empty spaces at the end of a string <aperrin@davis.DEMOG.Berkeley.EDU>
Re: Remove all empty spaces at the end of a string <fortkid@bellsouth.net>
Re: Saving Uploaded Files using CGI.pm (Mike)
Re: Saving Uploaded Files using CGI.pm (T. Postel)
Re: Saving Uploaded Files using CGI.pm <rootbeer@redcat.com>
Re: sort() <makarand_kulkarni@My-Deja.com>
Re: sprintf in CGI <lr@hpl.hp.com>
Re: sprintf in CGI jdaves@gilanet.com
Re: sprintf in CGI <makarand_kulkarni@My-Deja.com>
Re: VMS Perl system() truncating lines <dan@tuatha.sidhe.org>
When do undefined null scalars become automatically def <franl-removethis@world.omitthis.std.com>
Re: When do undefined null scalars become automatically <rootbeer@redcat.com>
Re: Where is a clear, complete explanation of using per (Tad McClellan)
Re: Where is a clear, complete explanation of using per (jkroger)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 3 May 2000 13:23:14 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Reading and Writing to a file
Message-Id: <slrn8h0o42.81q.tadmc@magna.metronet.com>
On Wed, 03 May 2000 16:00:17 GMT, exhacker@my-deja.com <exhacker@my-deja.com> wrote:
>In article <Pine.A41.4.10.10005031032360.18964-
>100000@ginger.libs.uga.edu>,
> Brad Baxter <bmb@ginger.libs.uga.edu> wrote:
>> On Wed, 26 Apr 2000, Carter Hamilton wrote:
>>
>> > I would like to open a text file and append something to the end of
>certain
>> > lines. Is there any way to do this without copying the information
>to a new
>> > file?
What is the objection to copying it to a new file?
That approach is much easier than the alternatives, especially
if you let perl do it for you.
>> perldoc -q "how do i change one line in a file"
>You would use the -i switch to Perl, which specifies that files
>processed with the <> construct be edited in-place.
1) that is what the FAQ referenced above says. You didn't
even read the FAQ, did you? (that pretty much explains
the "ex" in your email address :-)
2) that *does* copy the info to a new file, something the
OP specifically disallowed.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 3 May 2000 16:47:20 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Reading and Writing to a file
Message-Id: <slrn8h142o.8ll.tadmc@magna.metronet.com>
On Wed, 03 May 2000 13:50:58 -0700, Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
>My skill level is well
>beyond any need for training wheels.
Please do not post to the wrong newsgroup again.
Surely you meant for that to go to rec.humor.funny ?
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 03 May 2000 16:31:39 -0500
From: "Andrew N. McGuire" <andrew.mcguire@walgreens.com>
Subject: Re: Reading and Writing to a file
Message-Id: <39109ABB.1006C5E6@walgreens.com>
"Godzilla!" wrote:
>
> > On Wed, 26 Apr 2000, Carter Hamilton asks for help:
>
> > I would like to open a text file and append something
> > to the end of certain lines. Is there any way to do
> > this without copying the information to a new
> > file? I would like to do something like this:
>
> > while (<TEXT>) {
> > if (/$pattern/) {
> > print TEXT chomp($_) . $newStuff . "\n";
>
> Open your data base for both read and write.
> Test each line for your conditional.
> If conditional is true, chomp and append newstuff.
> Print to your data base.
>
> Here is a simple test script you may
> modify and adapt if you wish. It can
> be run from the internet if needed by
> uploading my script and by uploading a
> test.txt with contents as shown with
> read and write permissions on.
>
> Contents of test.txt are first,
> my test script next, then results.
>
> Godzilla!
>
> ============
>
> CONTENTS OF TEST.TXT :
>
> false statement
> true statement
> false statement
> true statement
>
> TEST SCRIPT:
>
> #!/usr/local/bin/perl
No '-w' or 'use strict' present.
> print "Content-Type: text/plain\n\n";
Why?
> $newstuff = "append this";
>
> open (TEST, "+<test.txt");
No diagnostic? How will you know if the open() was successful?
Also it is generally accepted that there should be no white
space before the leading paren of a function call.
> @Test = <TEST>;
Why, this model does not scale well for large files.
Use 'while (<TEST>) { ... }' instead.
> foreach $test_line (@Test)
This would not be necessary had you used 'while' instead.
> {
> if ($test_line =~ /true statement/)
If you had used $_ instead, this could be simplified to
'if (/true statement/) { ... }'.
> {
> chomp ($test_line);
You remove the "\n" ...
> $test_line = join (" ", $test_line, $newstuff, "\n");
Only to put it back on...
> }
> print TEST $test_line;
No call to seek() before writing, so you append.
> print $test_line;
> }
>
> close (TEST);
>
> exit;
Why, it would have happened anyway. Maybe you
mean 'exit(1)', becuase this script is one big
error.
> PRINTED RESULTS:
>
> false statement
> true statement append this
> false statement
> true statement append this
RESULTS PRINTED TO FILE:
false statement
true statement
false statement
true statement
Regards,
anm
--
Andrew N. McGuire
andrew.mcguire@walgreens.com
perl -ne '/=item \* (.*?\?)/ && push @x,$1}{print "$x[rand @x]\n"' *.pod
------------------------------
Date: Wed, 03 May 2000 16:46:26 -0500
From: "Andrew N. McGuire" <andrew.mcguire@walgreens.com>
Subject: Re: Reading and Writing to a file
Message-Id: <39109E32.262E1325@walgreens.com>
"Godzilla!" wrote:
>
> Larry Rosler wrote:
>
> > In article <391064F5.65224160@stomp.stomp.tokyo> on Wed, 03 May 2000
> > 10:42:13 -0700, Godzilla! <godzilla@stomp.stomp.tokyo> says...
>
> > You MUST do the following operation before rewriting the file:
>
> > seek TEST, 0, 0 or die "Couldn't rewind 'test.txt'. $!\n";
>
> No, I do not have to do this. I write code
> which works, usually first time through,
Yeah, right.. Just because it compiles doesn't
mean it works.
> although not always bug or glitch free.
> Additionally, I test code before posting.
Really, then how come your code was broken?
> This code works perfect. Who are you to
> say I " must " use whatever?
Obviously a better programmer than you are.
And someone who gives a damn about what they post.
> I am sure
> many need pragma hints and diagnostics
> to get their programs to run. I am not
> one of those. My skill level is well
> beyond any need for training wheels.
Sure.
Here, this does what the OP wanted, and
is not broke, like your code:
perl -wpi.bak -e 'chomp and $_ .= "and stuff.\n" if /true statement/'
test.txt
so does this:
perl -wpi.bak -e 's/(true statement)/$1 and stuff./' test.txt
Pardon the '-w' training wheels. ;^)
> > (I refuse to post code here without appropriate diagnostics, though that
> > doesn't trouble you at all.)
>
> Last code of yours I tested would not compile.
> It is bad code as is ten to twenty percent of
> all code you post. Stick with those training
> wheels a while longer. You will eventually
> reach my level of programming skill.
Oh jeez. One day, I too, aspire to be as you are. Not.
You are laying it on a bit thick here, don't you think?
Regards,
anm
--
Andrew N. McGuire
andrew.mcguire@walgreens.com
perl -ne '/=item \* (.*?\?)/ && push @x,$1}{print "$x[rand @x]\n"' *.pod
------------------------------
Date: Wed, 03 May 2000 14:49:35 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Reading and Writing to a file
Message-Id: <39109EEF.BA7E3D4E@vpservices.com>
"Godzilla!" wrote:
> CONTENTS OF TEST.TXT :
>
> false statement
> true statement
> false statement
> true statement
Contents of Godzilla's answer to this question:
false statement
baloney
flawed and misleading code
horse puckey
false statement
--
Jeff
------------------------------
Date: Wed, 3 May 2000 12:23:16 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Reading and Writing to a file
Message-Id: <MPG.137a1c7e94d944af98a9dc@nntp.hpl.hp.com>
In article <391064F5.65224160@stomp.stomp.tokyo> on Wed, 03 May 2000
10:42:13 -0700, Godzilla! <godzilla@stomp.stomp.tokyo> says...
...
> #!/usr/local/bin/perl
>
> print "Content-Type: text/plain\n\n";
>
> $newstuff = "append this";
>
> open (TEST, "+<test.txt");
>
> @Test = <TEST>;
>
> foreach $test_line (@Test)
> {
> if ($test_line =~ /true statement/)
> {
> chomp ($test_line);
> $test_line = join (" ", $test_line, $newstuff, "\n");
> }
> print TEST $test_line;
> print $test_line;
> }
>
> close (TEST);
>
> exit;
>
>
> PRINTED RESULTS:
>
> false statement
> true statement append this
> false statement
> true statement append this
Yes, those are the printed results, but not the results in the
supposedly updated file. But you don't feel any need to test what you
post, do you?
You MUST do the following operation before rewriting the file:
seek TEST, 0, 0 or die "Couldn't rewind 'test.txt'. $!\n";
(I refuse to post code here without appropriate diagnostics, though that
doesn't trouble you at all.)
And then, for the general case where the new file length may be shorter
than the original:
truncate TEST, 0 or die "Couldn't truncate 'test.txt'. $!\n";
As for the whole approach, it stinketh to Heaven, because a mishap such
as a system crash while rewriting the file could corrupt the data
irretrievably.
I doubt that there are still readers here who are not yet immunized to
your poison, but new ones may come along at any time. Read the FAQ, not
this, newbies!
As always, your code is "... out of joint: O cursed spite, That ever I
was born to set it right!" (Hamlet, Act I, Scene 5 -- but you knew
that!)
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 03 May 2000 13:50:58 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Reading and Writing to a file
Message-Id: <39109132.9F0CB6B6@stomp.stomp.tokyo>
Larry Rosler wrote:
> In article <391064F5.65224160@stomp.stomp.tokyo> on Wed, 03 May 2000
> 10:42:13 -0700, Godzilla! <godzilla@stomp.stomp.tokyo> says...
> You MUST do the following operation before rewriting the file:
> seek TEST, 0, 0 or die "Couldn't rewind 'test.txt'. $!\n";
No, I do not have to do this. I write code
which works, usually first time through,
although not always bug or glitch free.
Additionally, I test code before posting.
This code works perfect. Who are you to
say I " must " use whatever? I am sure
many need pragma hints and diagnostics
to get their programs to run. I am not
one of those. My skill level is well
beyond any need for training wheels.
> (I refuse to post code here without appropriate diagnostics, though that
> doesn't trouble you at all.)
Last code of yours I tested would not compile.
It is bad code as is ten to twenty percent of
all code you post. Stick with those training
wheels a while longer. You will eventually
reach my level of programming skill.
=)
Godzilla!
------------------------------
Date: Wed, 3 May 2000 14:42:46 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Reading and Writing to a file
Message-Id: <MPG.137a3d28388b746598a9e4@nntp.hpl.hp.com>
[Your mailer doesn't produce proper References: headers, so your posts
don't thread properly. But why should I be surprised? Nothing you do
conforms to normal human expectations. But trolls aren't human, are
they?]
In article <39109132.9F0CB6B6@stomp.stomp.tokyo> on Wed, 03 May 2000
13:50:58 -0700, Godzilla! <godzilla@stomp.stomp.tokyo> says...
> Larry Rosler wrote:
>
> > In article <391064F5.65224160@stomp.stomp.tokyo> on Wed, 03 May 2000
> > 10:42:13 -0700, Godzilla! <godzilla@stomp.stomp.tokyo> says...
>
> > You MUST do the following operation before rewriting the file:
>
> > seek TEST, 0, 0 or die "Couldn't rewind 'test.txt'. $!\n";
>
> No, I do not have to do this. I write code
> which works, usually first time through,
> although not always bug or glitch free.
> Additionally, I test code before posting.
> This code works perfect.
What operating environment supports your assertion? I offer proof below
that is isn't true, at least on two modern operating systems.
> Who are you to
> say I " must " use whatever? I am sure
> many need pragma hints and diagnostics
> to get their programs to run. I am not
> one of those. My skill level is well
> beyond any need for training wheels.
I am not talking about 'pragma hints and diagnostics', which you
blithely dismiss as 'training wheels'. I am talking about programs that
simply don't do what you claim they do.
Here is a complete recapitulation of your code, with some extra
'training wheels' added. Others may choose to run this themselves, to
verify my assertions. Reproducible results are the centerpiece of the
Scientific Method, which as a self-described liberal-arts person, you
seem to feel not to apply to you or to your work.
#!/usr/bin/perl -w
use strict;
my $newstuff = 'append this';
my $file = 'e:/test/test.txt';
open TEST, "+<$file" or die "Couldn't open '$file'. $!\n";
print -M $file, "\n";
my @Test = <TEST>;
#seek TEST, 0, 0 or die "Couldn't rewind '$file'. $!\n";
foreach my $test_line (@Test)
{
if ($test_line =~ /true statement/)
{
chomp ($test_line);
$test_line = join (" ", $test_line, $newstuff, "\n");
}
print TEST $test_line or die "Couldn't print to '$file'. $!\n";
print $test_line;
}
close (TEST);
print -M $file, "\n";
__END__
The test file is as in your code:
false statement
true statement
false statement
true statement
When run as shown, without the MANDATORY seek statement, the results
are:
Unix (HP-UX 10.20): The file is appended to. Four lines become eight
lines.
Windows NT 4.0 SP5: The file is not written to. The print statement
fails, though the diagnostic gives nothing in $!.
> > (I refuse to post code here without appropriate diagnostics, though that
> > doesn't trouble you at all.)
>
> Last code of yours I tested would not compile.
Probably because it wasn't written for Perl 4. Would you care to be
specific for once? Deja.com will help you, if you can't remember.
<URL:http://www.deja.com/home_ps.shtml>
> It is bad code as is ten to twenty percent of
> all code you post. Stick with those training
> wheels a while longer. You will eventually
> reach my level of programming skill.
>
> =)
That is a higher goal than I dare aspire to. My wings might melt.
=(
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 03 May 2000 16:49:51 -0500
From: "Andrew N. McGuire" <andrew.mcguire@walgreens.com>
Subject: Re: Reading and Writing to a file
Message-Id: <39109EFF.80415BCE@walgreens.com>
"Andrew N. McGuire" wrote:
>
> "Godzilla!" wrote:
> >
> > > On Wed, 26 Apr 2000, Carter Hamilton asks for help:
[ snip of Godzilla droppings ]
>
> RESULTS PRINTED TO FILE:
>
> false statement
> true statement
> false statement
> true statement
[ snip ]
Apologies, that should have read:
RESULTS PRINTED TO FILE:
false statement
true statement
false statement
true statement
false statement
true statement append this
false statement
true statement append this
Cheers,
anm
--
Andrew N. McGuire
andrew.mcguire@walgreens.com
perl -ne '/=item \* (.*?\?)/ && push @x,$1}{print "$x[rand @x]\n"' *.pod
------------------------------
Date: Wed, 03 May 2000 14:56:58 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Reading and Writing to a file
Message-Id: <3910A0AA.196F315B@vpservices.com>
"Andrew N. McGuire" wrote:
>
> "Andrew N. McGuire" wrote:
> >
> > "Godzilla!" wrote:
> > >
> > > > On Wed, 26 Apr 2000, Carter Hamilton asks for help:
>
> [ snip of Godzilla droppings ]
> >
> > RESULTS PRINTED TO FILE:
> >
> > false statement
> > true statement
> > false statement
> > true statement
>
> [ snip ]
>
> Apologies, that should have read:
>
> RESULTS PRINTED TO FILE:
>
> false statement
> true statement
> false statement
> true statement
> false statement
> true statement append this
> false statement
> true statement append this
>
Actaully, it depends on the platform. On win98 your first results are
what you end up with (i.e. no changes), on other platforms you get the
appending behaviour. Neither is what the OP requested or what G/PG said
they would be.
--
Jeff
------------------------------
Date: Wed, 03 May 2000 15:00:26 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Reading and Writing to a file
Message-Id: <3910A17A.687839AD@stomp.stomp.tokyo>
"Andrew N. McGuire" wrote:
> Apologies, that should have read:
* smiles *
"Here is a simple test script you may
modify and adapt if you wish."
Godzilla!
------------------------------
Date: Wed, 3 May 2000 16:35:13 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: reg expressions assistance
Message-Id: <slrn8h13c1.8j0.tadmc@magna.metronet.com>
On Wed, 03 May 2000 19:30:09 GMT, exhacker <fortkid@bellsouth.net> wrote:
>> I am trying to get an understanding of efficiency within a regular
^^^^^^^^^^
>> expression. I have some strings that come back from an application which
>> always seem to have a \n in the front and a \n in the back.
>
>If you want rid of all the newlines,
>
>$bird =~ s/\n//g;
That is not "efficient".
$bird =~ tr/\n//d;
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 03 May 2000 19:30:09 GMT
From: exhacker <fortkid@bellsouth.net>
Subject: Re: reg expressions assistance
Message-Id: <sh0vi1apa4n103@corp.supernews.com>
> I am trying to get an understanding of efficiency within a regular
> expression. I have some strings that come back from an application which
> always seem to have a \n in the front and a \n in the back.
If you want rid of all the newlines,
$bird =~ s/\n//g;
or just at the beginning and end of the line
$bird =~ s/^\n//;
$bird =~ s/\n$//;
exhacker
--
Posted via CNET Help.com
http://www.help.com/
------------------------------
Date: Wed, 3 May 2000 11:29:08 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Regex for not matching a particular string
Message-Id: <MPG.137a0fccd787fc3d98a9db@nntp.hpl.hp.com>
In article <Pine.A41.4.10.10005031003060.214170-
100000@holly.ColoState.EDU> on Wed, 3 May 2000 10:07:50 -0600, Mitesh
Desai <desaim@holly.ColoState.EDU> says...
> Is there a way of specifying a regular expression
> in perl for matching a line if it that does not
> contain a particular string?
>
> My problem is to find if the line contains 'abc',
> but the 'abc' is not followed by 'def'. This is
> not the exact problem, but the gist of it.
Use negative lookahead.
print "Matched 'abc' not followed by 'def'.\n" if /abc(?!.*def)/;
That checks for 'abc' not followed by 'def' anywhere in the line in $_.
Season to taste.
perldoc perlre
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 03 May 2000 21:27:26 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Regex for not matching a particular string
Message-Id: <sh16du2ga4n128@corp.supernews.com>
Mitesh Desai (desaim@holly.ColoState.EDU) wrote:
: Is there a way of specifying a regular expression
: in perl for matching a line if it that does not
: contain a particular string?
:
: My problem is to find if the line contains 'abc',
: but the 'abc' is not followed by 'def'. This is
: not the exact problem, but the gist of it.
If you mean "followed immediately", test
$string =~ /abc(?!def)/;
If you mean "followed anywhere in the string", test
$string =~ /abc(?!.*?def)/;
--
| Craig Berry - cberry@cinenet.net
--*-- http://www.cinenet.net/users/cberry/home.html
| "The road of Excess leads to the Palace
of Wisdom" - William Blake
------------------------------
Date: Wed, 03 May 2000 21:30:08 GMT
From: Daniel Pfeiffer <occitan@esperanto.org>
Subject: Re: Regexp speed (was: Help: bol regexp in split string)
Message-Id: <8eq5ob$v87$1@nnrp1.deja.com>
In article <8engok$vm2$1@nnrp1.deja.com>, I wrote:
> Well, I ran these two proggies with no other load on the machine
> through shell command "time" ten times, and
> $a='abcd';
> while($i++<1000000){
> $a = "$'$1$`" if $a =~ /(c)/;
> $a =~ /b/;
> }
> got an average user time of 24.49s, and
> $a='abcd';
> while($i++<1000000){
> my @a;
> $a = "$a[2]$a[1]$a[0]" if @a = split /(c)/, $a, 2;
> $a =~ /b/;
> }
> got an average user time of 40.92 -- way worse! (The 2nd re is just
> in case optimisations happen if calling the same one repeatedly.)
I just thought of a third variant, similar to the first while eviting $'
and friends.
$a='abcd';
while($i++<1000000){
$a = "$3$2$1" if $a =~ /(.*)(c)(.*)/;
$a =~ /b/;
}
got an average user time of 26.91s, 1% worse than using $', but maybe
worthwhile if there are a lot of other regexps in the programme. On the
other hand, here the two (.*) don't have much to match, the tradeoff
might be even worse in a real life application like my iPerl. I guess
I'll have to get around to measuring that later.
Till then, it seems like $` and $' are generally after all a good thing
where needed!
--
Bring text-docs to life! Erwecke Textdokumente zum Leben!
http://beam.to/iPerl/
Vivigu tekstodokumentojn!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 03 May 2000 22:02:36 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Regexp speed (was: Help: bol regexp in split string)
Message-Id: <x74s8fxpfo.fsf@home.sysarch.com>
>>>>> "DP" == Daniel Pfeiffer <occitan@esperanto.org> writes:
DP> Till then, it seems like $` and $' are generally after all a good thing
DP> where needed!
do you understand the slowdown of $` and $' at all? it has nothing to do
with the single regex where you use them. they slow down ALL other
regexes in your entire program because they require extra copies of the
string to be made in case you use those special vars.
there is no need for them programmatically as you can always use
grouping before and after so the rule is simply don't use them, period.
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: 03 May 2000 13:43:50 -0700
From: Andrew Perrin - Demography <aperrin@davis.DEMOG.Berkeley.EDU>
Subject: Re: Remove all empty spaces at the end of a string
Message-Id: <u5kbt2n2wl5.fsf@davis.DEMOG.Berkeley.EDU>
exhacker <fortkid@bellsouth.net> writes:
> $string =~ s/[\s]*$//;
^ ^^
Useless use of character class
Extra processing required to remove nonexistent spaces
$string =~ s/\s+$//;
--
---------------------------------------------------------------------
Andrew J. Perrin - aperrin@demog.berkeley.edu - NT/Unix Admin/Support
Department of Demography - University of California at Berkeley
2232 Piedmont Avenue #2120 - Berkeley, California, 94720-2120 USA
http://demog.berkeley.edu/~aperrin --------------------------SEIU1199
------------------------------
Date: Wed, 03 May 2000 19:30:11 GMT
From: exhacker <fortkid@bellsouth.net>
Subject: Re: Remove all empty spaces at the end of a string
Message-Id: <sh0vi37qa4n134@corp.supernews.com>
$string =~ s/[\s]*$//;
that should work for your purposes, reply if not.
Penpal International wrote:
>
> How can I remove all spaces at the the end of string?
>
>
> --
> Penpal International
> http://ppi.searchy.net/
> ppi@searchy.net
--
Posted via CNET Help.com
http://www.help.com/
------------------------------
Date: Wed, 3 May 2000 18:00:15 GMT
From: noSpam@hotmail.com (Mike)
Subject: Re: Saving Uploaded Files using CGI.pm
Message-Id: <39126295.2346113262@news.boeing.com>
On Tue, 2 May 2000 16:58:42 -0700, Tom Phoenix <rootbeer@redcat.com>
wrote:
>On Tue, 2 May 2000, Mike wrote:
>
>> I have looked at a couple of examples using CGI.pm to upload files.
>> Each of these examples do things like echo back the contents, etc.
>>
>> But none show how to actually save the file in a specific location.
>
>Do you know how to write a file of your own to a specific location, in a
>non-CGI program? It's done in the same basic way when using CGI.pm. See
>the docs for open() in the perlfunc manpage, the perlopentut manpage, or
>both. If you have further questions after reading those docs, feel free to
>ask again. Cheers!
I've written files to specific locations. But it always requires
open(), followed by creating some variables, then writing back to that
opened file, wherever it was opened.
But all of the examples that I have seen, where an upload is envolved,
open() the file to a temporary directory, read some data, echo it back
and don't ever write it to a new location.
So, I guess the answer is NO. I have never uploaded, and saved a file
to a new location. That is why I have asked the question.
I simply want to upload the file and then save it to a new location,
without having to open, read into a buffer, then write to a new file.
------------------------------
Date: Wed, 03 May 2000 18:33:27 GMT
From: T.Postel@ieee.org (T. Postel)
Subject: Re: Saving Uploaded Files using CGI.pm
Message-Id: <Xh_P4.7$lY4.1827@news2.randori.com>
noSpam@hotmail.com (Mike) wrote:
>On Tue, 2 May 2000 16:58:42 -0700, Tom Phoenix <rootbeer@redcat.com>
>wrote:
>
>>On Tue, 2 May 2000, Mike wrote:
>>
>>> I have looked at a couple of examples using CGI.pm to upload files.
>>> Each of these examples do things like echo back the contents, etc.
>>>
>>> But none show how to actually save the file in a specific location.
>>
>>Do you know how to write a file of your own to a specific location, in a
>>non-CGI program? It's done in the same basic way when using CGI.pm. See
>>the docs for open() in the perlfunc manpage, the perlopentut manpage, or
>>both. If you have further questions after reading those docs, feel free to
>>ask again. Cheers!
>
>I've written files to specific locations. But it always requires
>open(), followed by creating some variables, then writing back to that
>opened file, wherever it was opened.
>
>But all of the examples that I have seen, where an upload is envolved,
>open() the file to a temporary directory, read some data, echo it back
>and don't ever write it to a new location.
>
>So, I guess the answer is NO. I have never uploaded, and saved a file
>to a new location. That is why I have asked the question.
>
>I simply want to upload the file and then save it to a new location,
>without having to open, read into a buffer, then write to a new file.
As I understand it cgi.PM always writes to a buffer, I use this:
open(OUTFILE, ">$Filename") or die "failed to open $Filename: $!";
undef $BytesRead;
undef $Buffer;
while ($Bytes = read($File_Handle,$Buffer,1024)) {
$BytesRead += $Bytes;
print OUTFILE $Buffer;
}
close($File_Handle);
close(OUTFILE);
This is just a snippet, you'll need to declare the variables. I use $BytesRead
to check that I got the whole file.
hth.
While my e-mail address is not munged, | T.Postel@ieee.org
I probably won't read anything sent there. |
------------------------------
Date: Wed, 3 May 2000 11:43:11 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Saving Uploaded Files using CGI.pm
Message-Id: <Pine.GSO.4.10.10005031142020.13677-100000@user2.teleport.com>
On Wed, 3 May 2000, Mike wrote:
> I simply want to upload the file and then save it to a new location,
> without having to open, read into a buffer, then write to a new file.
Well, perhaps the rename() function will let you move it, or you might be
able to use move() from File::Copy, as another poster suggested. Does that
help? Good luck with it!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 03 May 2000 12:09:42 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: sort()
Message-Id: <39107976.A65E7327@My-Deja.com>
> can anyone tell me what sort algorithm is used
> on sort() in perl?
>
Quicksort
> what is perl interpreted into? if i have the
> following statement, what would it be interpreted
> into?
>
> @out=sort(@string_list);
Read this
http://www.hpl.hp.com/personal/Larry_Rosler/sort/sorting.html
------------------------------
Date: Wed, 3 May 2000 11:23:38 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: sprintf in CGI
Message-Id: <MPG.137a0e80e2d19ea798a9da@nntp.hpl.hp.com>
In article <39104E81.8C3A91F4@nospam.com> on Wed, 03 May 2000 18:06:25
+0200, Marco Natoni <blah@nospam.com> says...
> jdaves@gilanet.com wrote:
> > I'm trying to put a nicely formatted string into a CGI list
> > box (essentially, to get multiple columns in a list box). I'm
> > using the CGI modules. My code goes something like this:
>
> [...]
>
> > Unfortunately, all the formatting gets lost in the scrolling_list.
>
> Are you sure that HTML provides that feature? I am not: your browser
> should treat any number of consecutive "blank" character as one only, in
> form elements too.
That isn't a Perl issue. But a Perl solution *might* be (I'm not going
to test it):
s/ / /g
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 03 May 2000 19:06:58 GMT
From: jdaves@gilanet.com
Subject: Re: sprintf in CGI
Message-Id: <8eptc3$kut$1@nnrp1.deja.com>
(Smarting only slightly from the ever-so-mild burns) oh well. . .
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 03 May 2000 12:28:04 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: sprintf in CGI
Message-Id: <39107DC4.74646D0@My-Deja.com>
>
> Unfortunately, all the formatting gets lost in the scrolling_list. What
> I'd like to do is this:
> -Use a fixed font (so things line up)
> -Retain spacing as specified in the sprintf format string
You can set font using simple style sheets ( but
spaces from your sprintf should be represented
using wherever needed ).
eg
<style>
.small {font-size: 8pt; color: #FF0000; font-family: Arial;}
</style>
<p class="small">
<form class="small">
<select>
<option>ABC123
<option>123ABC
</select>
</form>
</p>
------------------------------
Date: Wed, 03 May 2000 21:58:22 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: VMS Perl system() truncating lines
Message-Id: <2i1Q4.76723$hT2.327466@news1.rdc1.ct.home.com>
In comp.lang.perl.misc T.E.Dickey <dickey@shell.clark.net> wrote:
> In comp.os.vms Larry Rosler <lr@hpl.hp.com> wrote:
>> In article <8ekqd3$ver$1@nnrp1.deja.com> on Mon, 01 May 2000 20:45:28
>> GMT, ewilts@my-deja.com <ewilts@my-deja.com> says...
>>> One of my developers is reporting that the Perl system() call is
>>> truncating the argument to 256 characters. I'm running Perl 5.005_03.
>>>
>>> Is this a known limitation? Can this limit to be expanded to 1K or
>>> more?
>> The limitation is not in Perl. It might well be in the command
>> processor that the system() call is invoking. One way to avoid the
>> limit would be to supply a list of arguments to system(), instead of a
>> long string that requires parsing by the command processor.
> but isn't the command-line limit still 1k?
> (256 sounds like reading/writing a mailbox rather than the command line).
The mailbox limit's a bit larger than that. You're hitting the DCL
256-character command line limit here. I'm not sure there's a whole lot
you can do about it, unfortunately.
Dan
------------------------------
Date: Wed, 3 May 2000 18:31:01 GMT
From: Francis Litterio <franl-removethis@world.omitthis.std.com>
Subject: When do undefined null scalars become automatically defined?
Message-Id: <m3u2gf7afu.fsf@franl.andover.net>
On page 46 of "Programming Perl, 2nd Edition", under the heading "Boolean
Context", it says:
An undefined null scalar may become defined the first time you
use it as if it were defined, but prior to that you can use the
defined operator to determine whether the value is defined or
not.
Can someone give an example of an undefined null scalar becoming "defined
the first time you use it as if it were defined"? I just don't see that
the authors were driving at in the above quoted text.
--
Francis Litterio
franl-removethis@world.std.omit-this.com
PGP public keys available on keyservers.
------------------------------
Date: Wed, 3 May 2000 11:58:01 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: When do undefined null scalars become automatically defined?
Message-Id: <Pine.GSO.4.10.10005031154260.13677-100000@user2.teleport.com>
On Wed, 3 May 2000, Francis Litterio wrote:
> On page 46 of "Programming Perl, 2nd Edition", under the heading "Boolean
> Context", it says:
>
> An undefined null scalar may become defined the first time you
> use it as if it were defined, but prior to that you can use the
> defined operator to determine whether the value is defined or
> not.
>
> Can someone give an example of an undefined null scalar becoming
> "defined the first time you use it as if it were defined"? I just
> don't see that the authors were driving at in the above quoted text.
I don't see it either, unless it's autovivification.
sub test_def { defined(shift) ? "defined\n" : "undef\n" }
print "fred is ", test_def $fred;
$fred->[2] = "anything";
print "fred is ", test_def $fred;
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 3 May 2000 13:41:31 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Where is a clear, complete explanation of using perldebug?
Message-Id: <slrn8h0p6b.81q.tadmc@magna.metronet.com>
On Wed, 03 May 2000 12:12:52 -0400, jkroger <jkrogerSPAMBLOCKER@earthlink.net> wrote:
>I have before me Learning Perl, Perl Cookbook, and Programming Perl. I
>also have open in a window perldoc perldebug.
>It's easy to see why unix is not ready for prime time; this even though
^^^^
Eh?
This is the first mention of unix in your post.
Did you mean to say "Perl" there instead?
Perl isn't Unix.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 03 May 2000 16:40:57 -0400
From: jkrogerSPAMBLOCKER@earthlink.net (jkroger)
Subject: Re: Where is a clear, complete explanation of using perldebug?
Message-Id: <jkrogerSPAMBLOCKER-0305001640570001@tritone.csbmb.princeton.edu>
In article <slrn8h0p6b.81q.tadmc@magna.metronet.com>, tadmc@metronet.com
(Tad McClellan) wrote:
> On Wed, 03 May 2000 12:12:52 -0400, jkroger
<jkrogerSPAMBLOCKER@earthlink.net> wrote:
>
> >I have before me Learning Perl, Perl Cookbook, and Programming Perl. I
> >also have open in a window perldoc perldebug.
>
> >It's easy to see why unix is not ready for prime time; this even though
> ^^^^
>
> Eh?
>
> This is the first mention of unix in your post.
>
> Did you mean to say "Perl" there instead?
>
> Perl isn't Unix.
Don't you mean, "Gnu's not unix?"
Jim
------------------------------
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 V9 Issue 2938
**************************************