[15531] in Perl-Users-Digest
Perl-Users Digest, Issue: 2941 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 3 21:15:32 2000
Date: Wed, 3 May 2000 18: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: <957402924-v9-i2941@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 3 May 2000 Volume: 9 Number: 2941
Today's topics:
Re: Reading and Writing to a file <jeff@vpservices.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 <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 <godzilla@stomp.stomp.tokyo>
Re: Reading and Writing to a file (brian d foy)
Re: Reading and Writing to a file <lr@hpl.hp.com>
recursive function <aureld@free.fr>
Re: recursive function <mjcarman@home.com>
Re: recursive function <rootbeer@redcat.com>
Re: Saving Uploaded Files using CGI.pm (Mike)
Re: Saving Uploaded Files using CGI.pm <rootbeer@redcat.com>
Re: Saving Uploaded Files using CGI.pm <lr@hpl.hp.com>
Re: tricking the regex syntax <lr@hpl.hp.com>
Two Perl Syntax Question (Iali0719)
Re: Two Perl Syntax Question <rootbeer@redcat.com>
Re: Two Perl Syntax Question <lr@hpl.hp.com>
use constant and modules <remarqNOreSPAM@dosser.org.invalid>
Re: use constant and modules <rootbeer@redcat.com>
Re: VMS Perl system() truncating lines <gellyfish@gellyfish.com>
wait command or similar (Jonas Nilsson)
Re: wait command or similar <Jonathan.L.Ericson@jpl.nasa.gov>
Re: wait command or similar <rootbeer@redcat.com>
Re: wait command or similar <lauren_smith13@hotmail.com>
Re: Wanted: GUI interface for MySQL (AL3)
Re: When do undefined null scalars become automatically <aqumsieh@hyperchip.com>
Re: where is the getopt::Std module <makarand_kulkarni@My-Deja.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 03 May 2000 15:11:28 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Reading and Writing to a file
Message-Id: <3910A410.2AD3B5F3@vpservices.com>
"Godzilla!" wrote:
>
> "Andrew N. McGuire" wrote:
>
> > Apologies, that should have read:
>
> * smiles *
Smiling at what? The only thing Andrew goofed on was that there are two
different ways that your script has of failing rather than only one as
he originally thought.
--
Jeff
------------------------------
Date: Wed, 03 May 2000 15:25:31 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Reading and Writing to a file
Message-Id: <3910A75B.B7E319F1@stomp.stomp.tokyo>
Jeff Zucker wrote:
> Smiling at what? The only thing Andrew goofed on was that there are two
> different ways that your script has of failing rather than only one as
> he originally thought.
"Here is a simple test script you may
modify and adapt if you wish."
You people are always belly aching you shouldn't
have to write code for people; they should figure
it out on their own. Now you belly ache because
I didn't write full code for someone. You will
find it challenging to both have and eat your
hypocrisy cake.
*snaps her fingers*
Wallah! Served on a silver platter with
no challenge presented, no learning afforded,
just as the originating author asked and,
contrary to your constant bellyaching about
not dishing all things out on a silver platter.
====
#!/usr/local/bin/perl
print "Content-Type: text/plain\n\n";
$newstuff = "append this";
open (TEST, "test.txt");
@Test = <TEST>;
close (TEST);
open (NEWFILE, ">test.txt");
foreach $new_line (@Test)
{
if ($new_line =~ /true statement/)
{
chomp ($new_line);
$new_line = join (" ", $new_line, $newstuff, "\n");
}
print NEWFILE $new_line;
print $new_line;
}
close (NEWFILE);
exit;
PRINTED RESULTS FOR BOTH MONITOR AND TEST.TXT :
false statement
true statement append this
false statement
true statement append this
------------------------------
Date: Wed, 3 May 2000 15:31:19 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Reading and Writing to a file
Message-Id: <MPG.137a488dd27651a798a9e7@nntp.hpl.hp.com>
In article <39109ABB.1006C5E6@walgreens.com> on Wed, 03 May 2000
16:31:39 -0500, Andrew N. McGuire <andrew.mcguire@walgreens.com> says...
> "Godzilla!" wrote:
...
> > 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.
...
> > print "Content-Type: text/plain\n\n";
>
> Why?
See above. The troll wants the program to be runnable from the
Internet. I would do it this way, though:
print "Content-Type: text/plain\n\n" if $ENV{REQUEST_METHOD};
> > $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.
I don't use a leading paren there at all. But I think 'generally
accepted' is a throwback to the Bad Old Days when cpp(1) couldn't
recognize a macro with arguments if the invocation had a space before
the leading paren. Compared to the rest of this farrago, it is a
sylistic nit on a pile of shit.
> > @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.
You missed the point, which is to do an 'in situ' modification of the
file. You'd better slurp it all before rewriting.
...
> > chomp ($test_line);
>
> You remove the "\n" ...
>
> > $test_line = join (" ", $test_line, $newstuff, "\n");
>
> Only to put it back on...
In a different place. This is actually OK, mirabile dictu! Though the
join() looks fussy and throws in a gratuitous end space before the
newline:
$test_line .= " $newstuff\n";
A minimizer would throw the space and newline into $newstuff, as well as
an underscore to separate the words: $new_stuff.
> > }
> > print TEST $test_line;
>
> No call to seek() before writing, so you append.
Or don't do anything at all on some systems, because of uncleared EOF, I
conjecture. See the other responses.
> > print $test_line;
> > }
> >
> > close (TEST);
> >
> > exit;
>
> Why, it would have happened anyway. Maybe you
> mean 'exit(1)', becuase this script is one big
> error.
Yes. Too bad I have to add your few errors to the troll's gross
misfeasance.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 03 May 2000 15:55:04 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Reading and Writing to a file
Message-Id: <3910AE48.68EC554B@vpservices.com>
"Godzilla!" wrote:
>
> You people are always belly aching you shouldn't
> have to write code for people; they should figure
> it out on their own. Now you belly ache because
> I didn't write full code for someone.
No, I bellyache because you wrote code that did not work, and did not
create the file that you said it created and then you did not believe
Larry when he told you that.
> open (NEWFILE, ">test.txt");
Well, that opens a new file which is what the original poster asked not
to do and you ignored everyone's advice not to slurp the entire file
into an array and various other more minor things, but yes, this new
script you sent at least works and does what you say it will do. Good
job! No more bellyaching from me today. :-)
--
Jeff
------------------------------
Date: Wed, 3 May 2000 16:00:27 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Reading and Writing to a file
Message-Id: <MPG.137a4f65d8f413b998a9e9@nntp.hpl.hp.com>
In article <3910A75B.B7E319F1@stomp.stomp.tokyo> on Wed, 03 May 2000
15:25:31 -0700, Godzilla! <godzilla@stomp.stomp.tokyo> says...
> Jeff Zucker wrote:
> > Smiling at what? The only thing Andrew goofed on was that there are two
> > different ways that your script has of failing rather than only one as
> > he originally thought.
>
> "Here is a simple test script you may
> modify and adapt if you wish."
>
> You people are always belly aching you shouldn't
> have to write code for people; they should figure
> it out on their own. Now you belly ache because
> I didn't write full code for someone. You will
> find it challenging to both have and eat your
> hypocrisy cake.
BULLSHIT! as usual. If what you say is so, why did you say this
earlier:
I write code
which works, usually first time through,
although not always bug or glitch free.
Additionally, I test code before posting.
Sometimes we post sketches, identifying them as such. Sometimes we post
working code, having tested it as such. Yours is just a damned lie.
> *snaps her fingers*
>
> Wallah! Served on a silver platter with
> no challenge presented, no learning afforded,
> just as the originating author asked and,
> contrary to your constant bellyaching about
> not dishing all things out on a silver platter.
SNIP of useless code that still slurps the file for no reason at all,
and -- most important -- omits the crucial final step of renaming the
new file to that of the original file, as requested by the original
poster.
Concluding (I hope!) note:
Signal: The response that referred the original poster to the FAQ.
Noise: Your response and the flurry of followups you always
provoke from those of us who feel responsible not to let
your piles of shit just sit there for eternity unremarked.
--
(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:18:17 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Reading and Writing to a file
Message-Id: <3910B3B9.32D6D326@stomp.stomp.tokyo>
Jeff Zucker wrote:
> Well, that opens a new file which is what the original poster asked not
> to do and you ignored everyone's advice not to slurp the entire file
> into an array and various other more minor things, but yes, this new
> script you sent at least works and does what you say it will do. Good
> job! No more bellyaching from me today. :-)
Not quite. It is not a new file, it is a rewrite
of the same file. Slippery semantics don't cut
it with me. This is cheating.
Standard method, rather than my schizoid method,
is to create a new file, delete the old file,
then rename the new file to the old file name.
This is what is meant by "creating a new file."
My code is infinitly more efficient and, in its
original format, presented the author with a
challenge to solve, presented the author with
a situation where he must learn. My indicating
"open for both read and write...." is more than
enough of a hint for a beginner with moderate
skills to solve this challenge I presented. I am
here to help people learn, not to dish out code
on a silver platter. My expectations are people
will carefully read my articles and give equally
careful attention to reading comprehension.
"...simple test script...modify...adapt...."
Slurp is most appropriate if you are going to
rewrite an entire file. It is extremely risky
to not slurp for an entire rewrite. On this,
you are dead wrong.
Incidently, there are some interesting articles
showing slurp to be more efficient than while.
Research will lead you to learning on this.
I have a link but it has been down for two
days now. When it comes back up, I will post.
Godzilla!
------------------------------
Date: Wed, 03 May 2000 16:26:01 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Reading and Writing to a file
Message-Id: <3910B589.A7248E6A@stomp.stomp.tokyo>
Larry Rosler wrote:
> [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?]
No, it is Supernews. Sucks to be Supernews. I am estimating
three out of ten articles don't show up on Supernews. I have
to pull them elsewhere and fake in a response.
For my articles, odds are fifty-fifty whether a post will
take at Supernews or not.
I object to your use of vulgarity in response to myself
along with objecting to your personally offensive remarks.
Your code , run under a common system, Perl version 5.003
with EMBED built under solaris, produces this:
0.000393518518518519
false statement
true statement append this
false statement
true statement append this
0
Bit of a mess compared to my code.
Godzilla!
------------------------------
Date: Wed, 03 May 2000 19:35:20 -0400
From: brian@smithrenaud.com (brian d foy)
Subject: Re: Reading and Writing to a file
Message-Id: <brian-ya02408000R0305001935200001@news.panix.com>
In article <3910B589.A7248E6A@stomp.stomp.tokyo>, "Godzilla!" <godzilla@stomp.stomp.tokyo> posted:
> Larry Rosler wrote:
> > [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?]
> No, it is Supernews. Sucks to be Supernews. I am estimating
> three out of ten articles don't show up on Supernews. I have
> to pull them elsewhere and fake in a response.
all that to hide your real identity: callgirl@la.znet.com
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Mongers <URL:http://www.perl.org/>
------------------------------
Date: Wed, 3 May 2000 16:52:44 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Reading and Writing to a file
Message-Id: <MPG.137a5ba8b82ac29498a9ec@nntp.hpl.hp.com>
In article <3910B589.A7248E6A@stomp.stomp.tokyo> on Wed, 03 May 2000
16:26:01 -0700, Godzilla! <godzilla@stomp.stomp.tokyo> says...
> Larry Rosler wrote:
>
> > [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?]
>
> No, it is Supernews. Sucks to be Supernews. I am estimating
> three out of ten articles don't show up on Supernews. I have
> to pull them elsewhere and fake in a response.
>
> For my articles, odds are fifty-fifty whether a post will
> take at Supernews or not.
Too bad. It makes things harder for everyone.
> I object to your use of vulgarity in response to myself
> along with objecting to your personally offensive remarks.
OK. My thermostat is set too high.
> Your code , run under a common system, Perl version 5.003
> with EMBED built under solaris, produces this:
>
> 0.000393518518518519
> false statement
> true statement append this
> false statement
> true statement append this
> 0
The '0' indicates that thw file was actually rewritten, but doesn't say
with what. I should have added code to reopen, reread and print the
file, to see whether it was rewritten or appended to. Perhaps you want
to do that.
Jeff Zucker wrote this, which confirmed my tests:
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.
> Bit of a mess compared to my code.
Because of extra tests and diagnostics, as it should be. But not enough
so.
--
(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:45:08 GMT
From: "Aurelien" <aureld@free.fr>
Subject: recursive function
Message-Id: <8l%P4.295$hJ2.1544254@nnrp1.proxad.net>
Hello !
I have a problem to read a directory with its sub-directories. Here is my
script. I don't understand why it don't work.
#! /usr/bin/perl -w
sub READ {
local($Dir, $File);
$Dir=$_[0];
if (substr($Dir,length($Dir)-1,1) ne "/") { $Dir=$Dir."/"; }
print "The current directory is $Dir: \n";
open(DIR,$Dir) or die("Unable to open $Dir !");
while(defined($File=readdir(DIR))) {
if (-d "$Dir$File" and $File ne "." and $File ne "..")
{ READ("$Dir$File"); }
if (-f "$Dir$File") { print "\t$File"; }
}
closedir(DIR);
}
READ(".");
-------------------------------------------------
/mydir
. .. file1 file2 file3
/mydir2
. .. otherfile1 otherfile2
/mydir3
. .. manyfiles
If I cd /mydir and I try to list "." I see all files of /mydir and of
/mydir/mydir2 but not that of /mydir/mydir3.
I think that at the return of the READ function, readdir stop to read the
$Dir directory. Why ?
Someone could help me please ?
Aurelien
------------------------------
Date: Wed, 03 May 2000 16:53:14 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: recursive function
Message-Id: <39109FCA.ACC264A4@home.com>
Tom Phoenix wrote:
>
> On Wed, 3 May 2000, Aurelien wrote:
>
> > I have a problem to read a directory with its sub-directories.
> > Here is my script. I don't understand why it don't work.
>
> It doesn't work because it should have been written with File::Find
> instead. :-)
>
> The other problem with it is that you're using a global directory
> handle.
And problem #3: He's using open() instead of opendir().
Tom's right, Aurelien. Use File::Find and save yourself some work.
Remember, laziness is a virtue. :)
-mjc
------------------------------
Date: Wed, 3 May 2000 13:18:34 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: recursive function
Message-Id: <Pine.GSO.4.10.10005031316090.13677-100000@user2.teleport.com>
On Wed, 3 May 2000, Aurelien wrote:
> I have a problem to read a directory with its sub-directories. Here is my
> script. I don't understand why it don't work.
It doesn't work because it should have been written with File::Find
instead. :-)
The other problem with it is that you're using a global directory handle.
But don't do it this way. Use File::Find instead. Your symbolic links will
thank you. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 3 May 2000 22:01:58 GMT
From: noSpam@hotmail.com (Mike)
Subject: Re: Saving Uploaded Files using CGI.pm
Message-Id: <3910a133.2362144614@news.boeing.com>
On Wed, 03 May 2000 18:33:27 GMT, T.Postel@ieee.org (T. Postel) wrote:
>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.
Thanks, but I already have it working with this snippet:
$path = "MyTest";
$title = param('title');
$desc = param('desc');
my $tmpfile=tmpFileName($file);
open(OUTFILE, "> $path");
while(read($file, $buffer, 1024)) {
print OUTFILE $buffer;
}
print OUTFILE "\n";
close(OUTFILE);
where $file is the file that is uploaded, but like my question asked,
is there a way to do this WITHOUT opening, reading and writing to the
output file. I know it's probably not a big deal but it seems a
little wasteful to have to read everything from one file and output it
to another.
Thanks
------------------------------
Date: Wed, 3 May 2000 15:45:22 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Saving Uploaded Files using CGI.pm
Message-Id: <Pine.GSO.4.10.10005031544340.13677-100000@user2.teleport.com>
On Wed, 3 May 2000, Mike wrote:
> open(OUTFILE, "> $path");
Even when your script is "just an example" (and perhaps especially in that
case!) you should _always_ check the return value after opening a file.
> is there a way to do this WITHOUT opening, reading and writing to the
> output file. I know it's probably not a big deal but it seems a
> little wasteful to have to read everything from one file and output it
> to another.
Have you tried the move() function from File::Copy yet?
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 3 May 2000 16:32:52 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Saving Uploaded Files using CGI.pm
Message-Id: <MPG.137a56fc8887527798a9ea@nntp.hpl.hp.com>
In article <Pine.GSO.4.10.10005021656400.13677-
100000@user2.teleport.com> on Tue, 2 May 2000 16:58:42 -0700, Tom
Phoenix <rootbeer@redcat.com> says...
> 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!
Well, here's a mystery.
The elderly book on CGI.pm has the following code:
$file = param('uplaod');
$tmpfile = tmpFileName($file);
rename $tmpfile,"./saved_file.out";
I tried code like this on my Perl 5.6.0 system, and it worked just fine
(modulo proper setting of the current directory, of course). But when I
searched the Perl 5.005_03 and 5.6.0 documentation for 'tmpFileName' it
wasn't there!
Would one recommend using this no-longer-documented function, which
meets the original poster's needs exactly? I would have no hesitation,
because it *is* in The Book. But why has its description disappeared?
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 3 May 2000 13:06:14 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: tricking the regex syntax
Message-Id: <MPG.137a26936a50538b98a9e0@nntp.hpl.hp.com>
In article <39105381.25761362@news.skynet.be> on Wed, 03 May 2000
17:00:37 GMT, Bart Lateur <bart.lateur@skynet.be> says...
+ Daniel Berger wrote:
+
+ >I would like to do the following:
+ >
+ >$opt = 'i';
+ >$line =~ /pattern/$opt
+ >
+ >Perl doesn't like that (and yes, I've tried different
+ >permutations of quotes, etc).
+ >
+ >Is there a way to make this work? Thanks in advance.
+
+ There is an alternative: see the "(?: ... )" syntax in "perlre". You
+ can put the options between the question mark and the colon.
+
+ /(?i:pattern)/
That creates a scoped option.
+ or, apparently, also:
+
+ /(?i)pattern/
That creates an unscoped option.
+ However, applying this directly to your problem, the result,
+ "/(?$opt:pattern)/" or "/(?$opt)pattern/" will suffer the same problem
+ as "/$pattern/": there's a need to compile the regex every time you
+ try to match anything. The //o option would help, but then, you can't
+ recompile, not in the same script run anyway.
So one could use run-time selection between two regexes:
($opt eq 'i' ? $line =~ /pattern/i : $line =~ /pattern/)
Decidedly uncool though. :-)
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 03 May 2000 22:59:06 GMT
From: iali0719@aol.com (Iali0719)
Subject: Two Perl Syntax Question
Message-Id: <20000503185906.22713.00002760@ng-cg1.aol.com>
I am a comparatively newbie to Perl and could not find the syntax to the do the
following two things in my Perl Reference Books:
1) How to separate characters in a string..i.e.
$myString = 1234;
Now how can I read individual characters within this string i.e. if I want to
break it into two characters each i.e. have one variable contain 12 and the
other 34. There are no special characters in between to use the split function
2)
For the following code
$myHexVal = 0x12AC;
$myString = "This is a hex number $HexVal";
How can I have $myString show the hex value of $HexVal instead of decimal such
that it shows "This is a hex number 12AC"
Any help would be greatly appreciated
------------------------------
Date: Wed, 3 May 2000 16:16:04 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Two Perl Syntax Question
Message-Id: <Pine.GSO.4.10.10005031612310.6766-100000@user2.teleport.com>
On 3 May 2000, Iali0719 wrote:
> 1) How to separate characters in a string..i.e.
> $myString = 1234;
>
> Now how can I read individual characters within this string i.e. if I
> want to break it into two characters each i.e. have one variable
> contain 12 and the other 34. There are no special characters in
> between to use the split function
I think you want substr(), but you may want a pattern match, some math
operations, or something else.
> $myHexVal = 0x12AC;
> $myString = "This is a hex number $HexVal";
>
> How can I have $myString show the hex value of $HexVal instead of
> decimal such that it shows "This is a hex number 12AC"
Do you mean like this?
$myHexVal = '12AC';
...and later, when you need to use it...
my $real_value = hex $myHexVal;
In general, when you have two unrelated questions, they should be posted
separately. This allows you to put a meaningful subject line onto your
postings. In addition, someone who knows how to answer one question and
not the other won't need to be reluctant to give you an answer.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 3 May 2000 17:43:34 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Two Perl Syntax Question
Message-Id: <MPG.137a678f1e6ab31398a9ef@nntp.hpl.hp.com>
[Not the finest Subject. Maybe asking two questions would have made it
easier to find appropriate Subjects for each of them. And please wrap
your lines at 72 characters in the future.]
In article <20000503185906.22713.00002760@ng-cg1.aol.com> on 03 May 2000
22:59:06 GMT, Iali0719 <iali0719@aol.com> says...
> I am a comparatively newbie to Perl and could not find the syntax to the do the
> following two things in my Perl Reference Books:
>
> 1) How to separate characters in a string..i.e.
> $myString = 1234;
As written, that is a number. But it will be converted to the string
'1234' when it needs to be, as in the code below.
> Now how can I read individual characters within this string i.e. if I want to
> break it into two characters each i.e. have one variable contain 12 and the
> other 34. There are no special characters in between to use the split function
There are several ways. This is one:
my @pairs = $myString =~ /..?/gs;
perldoc perlre
> 2)
> For the following code
>
> $myHexVal = 0x12AC;
> $myString = "This is a hex number $HexVal";
>
> How can I have $myString show the hex value of $HexVal instead of decimal such
> that it shows "This is a hex number 12AC"
$myString = sprintf 'This is a hex number %4.4X' => $myHexVal;
perldoc sprintf
--
(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:13:29 -0700
From: rdosser <remarqNOreSPAM@dosser.org.invalid>
Subject: use constant and modules
Message-Id: <23e691c1.d0b05e40@usw-ex0104-028.remarq.com>
Greetings,
I wish to define several constants using the 'use constant'
pragma in a module, and have scripts that 'use' that module
inherit the constants.
How?
Thanks,
Ralph Dosser
* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!
------------------------------
Date: Wed, 3 May 2000 13:25:13 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: use constant and modules
Message-Id: <Pine.GSO.4.10.10005031322590.13677-100000@user2.teleport.com>
On Wed, 3 May 2000, rdosser wrote:
> I wish to define several constants using the 'use constant'
> pragma in a module, and have scripts that 'use' that module
> inherit the constants.
>
> How?
Use the Exporter, in the usual way. See the docs for Exporter for the full
story. In general, though, you just want to name the things to be exported
in your @EXPORT or @EXPORT_OK arrays. h2xs will set most of this up for
you; don't forget that when you're starting your module. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 3 May 2000 18:40:12 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: VMS Perl system() truncating lines
Message-Id: <8epo9s$oma$1@orpheus.gellyfish.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).
Well I have :
/* Maximum length of arguments to `execve', including environment. */
#define _POSIX_ARG_MAX 4096
in the appropriate include file on my system. So that would suggest as
long as you use the multiple argument system() to ensure that the
command line is handed off to execv then you should have at least that
on POSIX compliant systems. Of course YMMV.
/J\
--
When you participate in sporting events, it's not wether you win or
lose. It's how drunk you get.
--
fortune oscar homer
------------------------------
Date: Wed, 03 May 2000 22:40:48 GMT
From: jonas.nilsson@mbox326.swipnet.se (Jonas Nilsson)
Subject: wait command or similar
Message-Id: <3910a9ce.830362@news1.tninet.se>
Hi.
Are there any command to halt the script? I want a script to wait for
5 seconds before it continue.
Jonas
------------------------------
Date: Wed, 03 May 2000 15:51:50 -0700
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: wait command or similar
Message-Id: <3910AD86.D4034C8D@jpl.nasa.gov>
Jonas Nilsson wrote:
> Are there any command to halt the script? I want a script to wait for
> 5 seconds before it continue.
Read all about it by typing 'perldoc -f sleep'.
Jon
--
Knowledge is that which remains when what is
learned is forgotten. - Mr. King
------------------------------
Date: Wed, 3 May 2000 16:02:57 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: wait command or similar
Message-Id: <Pine.GSO.4.10.10005031600400.6766-100000@user2.teleport.com>
On Wed, 3 May 2000, Jonas Nilsson wrote:
> Are there any command to halt the script? I want a script to wait for
> 5 seconds before it continue.
Do you mean sleep()? See the perlfunc manpage.
I feel as if I should point out that buffered output won't normally be
flushed before sleeping, so you may want to use $| (see the perlvar
manpage) to fix that.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 3 May 2000 16:07:32 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: wait command or similar
Message-Id: <8eqbeu$edt$1@brokaw.wa.com>
Jonas Nilsson <jonas.nilsson@mbox326.swipnet.se> wrote in message
news:3910a9ce.830362@news1.tninet.se...
> Hi.
> Are there any command to halt the script? I want a script to wait for
> 5 seconds before it continue.
perldoc -f sleep
Lauren
------------------------------
Date: Wed, 03 May 2000 23:22:55 GMT
From: rofl@eidosnet.co.uk (AL3)
Subject: Re: Wanted: GUI interface for MySQL
Message-Id: <3910b484.6244443@news.eidosnet.co.uk>
>>The download page for Mysql
>>http://mysql.com/download.html
>>has some downloads for graphical
>>MySQL clients
Killer! Thanks! I thought that site only had about one download. Now I
know better. I'll look at a few of the offerings.
A
------------------------------
Date: Wed, 03 May 2000 19:54:10 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: When do undefined null scalars become automatically defined?
Message-Id: <7a1z3jqujh.fsf@Merlin.i-did-not-set--mail-host-address--so-shoot-me>
Francis Litterio <franl-removethis@world.omitthis.std.com> writes:
> 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.
Hmmm... how about this:
my $x;
print "1. x = $x\n" if defined $x;
$x++;
print "2. x = $x\n" if defined $x;
__END__
2. x = 1
Initially, when we declared $x, it's value wasn't defined, so the
first print() statement wasn't executed. Then, we ask to increment $x
(which is undefined). Here, Perl automatically does the right thing,
and converts $x to a numeric 0 before incrementing it. The second
print() statement is executed, and shows us what happened to $x.
Does this help you?
--Ala
------------------------------
Date: Wed, 03 May 2000 12:38:49 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: where is the getopt::Std module
Message-Id: <39108049.4AA7C987@My-Deja.com>
> I want to download the getopt::Std module but could not find in CPAN. If
It is Getopt::Std
--
------------------------------
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 2941
**************************************