[22579] in Perl-Users-Digest
Perl-Users Digest, Issue: 4800 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 1 11:07:49 2003
Date: Tue, 1 Apr 2003 08:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 1 Apr 2003 Volume: 10 Number: 4800
Today's topics:
-M switch cannot be used the #! line (Tony Skelding)
Re: -M switch cannot be used the #! line <ubl@schaffhausen.de>
Re: -M switch cannot be used the #! line (Helgi Briem)
Re: Apache::Request is not good to me. (Randy Kobes)
Re: array or two hashes? (Bryan Castillo)
Re: Beginner's Perl question - trouble with a very simp <barryk2@SPAM-KILLER.mts.net>
Re: Double bit-negation (Anno Siegel)
Re: Double bit-negation <bongie@gmx.net>
Re: Loading STDOUT into a variable <sbour@niaid.nih.gov>
Re: Mail::Sender - comma separated email address lists (David Hiskiyahu)
Re: Match words between two files (Bryan Castillo)
OO problem with Data::Dumper and IO::Scalar <alex@nospamhoopsie.com>
passing variables to fork() <jhayden@usa.com>
Re: passing variables to fork() (Anno Siegel)
Re: Perl Debugger : ptkdb brianr@liffe.com
Re: Perl Interview Questions... <richard@zync.co.uk>
Re: Perl Interview Questions... (Tad McClellan)
Re: Perl Interview Questions... <steven.smolinski@sympatico.ca>
Re: Perl Interview Questions... <jurgenex@hotmail.com>
Re: search a dir for a file (Helgi Briem)
Re: search a dir for a file <noneya@biz.com>
Re: search a dir for a file <barryk2@SPAM-KILLER.mts.net>
Simple Filehandle Seek prob <daNOSPAM_beano@hotmail.com>
Re: Simple Filehandle Seek prob <josef.moellers@fujitsu-siemens.com>
Re: split map avoid error message (Tad McClellan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 1 Apr 2003 07:03:30 -0800
From: tony@skelding.co.uk (Tony Skelding)
Subject: -M switch cannot be used the #! line
Message-Id: <a78026a1.0304010603.a860dff@posting.google.com>
I want to use the -M switch on the #! line of a script. The Camel
says this cannot be done and there should be no need to do it - you
can always put a use in the file instead. For my purpose, putting a
use in the script is not an option - I can explain why if anyone is
interested.
The point is -M on the #! line does work. What you cannot seem to do
is call the import method (or any other function in the module)
without getting the error:
Too late for "-MMyModule" option at myScript.sh line 1.
I will have to accept that I cannot do what I want to do - at least
not the way I'm attempting to do it. What I'd like however, is for
someone to explain to me what is going on.
------------------------------
Date: Tue, 01 Apr 2003 17:25:49 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: -M switch cannot be used the #! line
Message-Id: <b6ce7q$jjj$1@news.dtag.de>
Tony Skelding wrote:
> I want to use the -M switch on the #! line of a script. The Camel
> says this cannot be done and there should be no need to do it - you
> can always put a use in the file instead. For my purpose, putting a
> use in the script is not an option - I can explain why if anyone is
> interested.
Just a little.
------------------------------
Date: Tue, 01 Apr 2003 15:46:29 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: -M switch cannot be used the #! line
Message-Id: <3e89b425.298701850@news.cis.dfn.de>
On 1 Apr 2003 07:03:30 -0800, tony@skelding.co.uk (Tony
Skelding) wrote:
>I want to use the -M switch on the #! line of a script. The Camel
>says this cannot be done and there should be no need to do it - you
>can always put a use in the file instead. For my purpose, putting a
>use in the script is not an option - I can explain why if anyone is
>interested.
I would be. Pretty bizarre limitation if you ask me.
--
Regards, Helgi Briem
helgi DOT briem AT decode DOT is
------------------------------
Date: 1 Apr 2003 14:15:43 GMT
From: randy@theoryx5.uwinnipeg.ca (Randy Kobes)
Subject: Re: Apache::Request is not good to me.
Message-Id: <slrnb8j75o.v60.randy@theoryx5.uwinnipeg.ca>
On Tue, 01 Apr 2003 03:05:57 +0200,
matthias tarasiewicz <mt-news@gmx.net> wrote:
>the package "Apache-Request" seems to have some problems,
>i can't install it.
>see the error output below, thanks so much for your help.
>
>cpan> install Apache::Request
[ .. ]
>t/cookie.....skipped
> all skipped: no reason given
>t/inherit....FAILED test 1
> Failed 1/1 tests, 0.00% okay
>t/request....FAILED tests 1-10
> Failed 10/10 tests, 0.00% okay
What happens if you run the tests while looged in as a user
other than root? Also, make sure that the port that the tests
use isn't being used by another process.
--
best regards,
randy kobes
------------------------------
Date: 1 Apr 2003 08:00:47 -0800
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: array or two hashes?
Message-Id: <1bff1830.0304010800.1aa94fc7@posting.google.com>
hannes michalek <hannes@michalek.de> wrote in message news:<b6bhr4$3jqer$1@ID-111424.news.dfncis.de>...
> i have two sub's in my script:
> 1) takes a directory and returns a list of files in that directory
> 2) takes a directory and returns the text of a certain line in a certain
> file in that directory.
>
> the problem is: the script does that very often and many times for the same
> directories. so i want to scan all directories at the beginning, storing
> filenames and text and using the stored ones later in the program.
>
> my question is, then:
> is it faster to use an array (directory,filenames,text) or two hashes
> (directory, filelist) and (directory,text)?
>
I would probably use a complex data stucture. I would probably have
the first level be a hash using the directory name as the key, the
value would be a hash (ref) where the key is the file, and then the
value of that hash would be the text. (Unless the files has more than
one text line, in which case you could use an array ref).
I think your problem lends itself to very well to an object. The
constructor would handle initialization and methods would retrieve
values out of the data structure. If you wanted to increase
efficiency (depending on the situation) you could have the methods
load the files in the directory and the text values lazily (You would
only open the directories and files on the first request).
> there are about 80 directories involved with 2-10 files (for the
> filenames-list) and 1 text-line each
>
>
> thanks!
>
> hannes
------------------------------
Date: Tue, 1 Apr 2003 08:40:27 -0600
From: Barry Kimelman <barryk2@SPAM-KILLER.mts.net>
Subject: Re: Beginner's Perl question - trouble with a very simple search/pattern matching script
Message-Id: <MPG.18f360d19f3ea8bf98977a@news.mts.net>
[This followup was posted to comp.lang.perl.misc]
In article <c4147d77.0304010212.437d4033@posting.google.com>, Martyn
Rankin (mgf_rankin@yahoo.com) says...
> Hi, I'm new to perl & am having trouble with a basic file - I want to
> open a file and loop through it to search for 6 different patterns
> (shown in the array '@mv') - these patterns are listed in output.txt,
> yet when I run the file I just get the following output:
>
> Looking for dog...failed
> Looking for cat...failed
> Looking for bird...failed
> Looking for fish...failed
>
> Can anyone see where I'm going wrong, or suggest a better way to do
> it? Thanks for your help in advance
>
> Martyn
>
>
> ----------------
>
> Match.pl
> ********
>
> #!/usr/local/bin/perl
> open (RESULTS,"output.txt") || die "Error - cannot open results
> file\n";
> @mv = ("dog", "cat", "bird", "fish");
> foreach $mv (@mv)
> {
> print "Looking for $mv...\n";
> if (/$mv/){
> print "mv ok\n";
> }
> else{
> print "failed\n";
> }
> }
> close (RESULTS);
>
> -------------------
>
> Output.txt
> **********
>
> dog
> cow
> cat
> sheep
> bird
> horse
> fish
>
You did *not* read in the text of the file !!!
open (RESULTS,"output.txt") ||
die("open failed : $!\n");
@records = <RESULTS>;
close RESULTS;
chomp @records;
@mv = ("dog", "cat", "bird", "fish");
foreach $mv ( @mv ) {
print "Looking for $mv...\n";
@match = grep /${mv}/,@records;
if ( 0 < @match ) {
print "mv ok\n";
}
else {
print "failed\n";
}
}
--
---------
Barry Kimelman
Winnipeg, Manitoba, Canada
email : bkimelman@hotmail.com
------------------------------
Date: 1 Apr 2003 11:22:05 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Double bit-negation
Message-Id: <b6bsot$485$2@mamenchi.zrz.TU-Berlin.DE>
Tony McNulty <acm2@ukc.ac.uk> wrote in comp.lang.perl.misc:
> I was playing in a golf game recently (badly) and this is the first time I
> came across the use of doubly negating:
>
> print~~grep$'==eval'+$_%$&%[$_/=$&]'x14,"@ARGV"=~/ .* /..$`
>
> This was one of the winning solutions, but i have no idea why they do it
> with that ~~
>
> Can anyone explain the point of it to me?
Probably just a way to put what follows in scalar context.
Anno
------------------------------
Date: Tue, 01 Apr 2003 16:55:56 +0200
From: "Harald H.-J. Bongartz" <bongie@gmx.net>
Subject: Re: Double bit-negation
Message-Id: <2334730.mR6ICJybx7@nyoga.dubu.de>
Tony McNulty wrote:
> I was playing in a golf game recently (badly) and this is the first
> time I came across the use of doubly negating:
>
> print~~grep$'==eval'+$_%$&%[$_/=$&]'x14,"@ARGV"=~/ .* /..$`
>
> This was one of the winning solutions, but i have no idea why they do
> it with that ~~
Because
~~ (list)
is shorter than
scalar (list)
:-)
Ciao,
Harald
--
Harald H.-J. Bongartz <bongie@gmx.net>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
People always ask me, "Where were you when Kennedy was shot?" Well, I
don't have an alibi. -- Emo Phillips
------------------------------
Date: Tue, 01 Apr 2003 08:56:09 -0500
From: Stephan Bour <sbour@niaid.nih.gov>
Subject: Re: Loading STDOUT into a variable
Message-Id: <BAAF04A9.6C34%sbour@niaid.nih.gov>
in article slrnb8i0a4.27c.tadmc@magna.augustmail.com, Tad McClellan at
tadmc@augustmail.com wrote on 3/31/03 22:02:
> Stephan Bour <sbour@niaid.nih.gov> wrote:
>
>> system("ifconfig");
>
>> there any way to assign the content of STDOUT to a variable
>
>
> perldoc -f system
>
>
> *plonk*
>
Thanks to those who actually provided help. I realize that most of the
newbie questions I (and others) ask can be solved by reading a FAQ or help
file somewhere. What you pros have to understand is that beginners don't
always know where and how to look for those simple answers. I never post a
question before doing my very best to answer it myself with the resources I
have. Please forgive me if that sometimes is not good enough.
Cheers,
Stephan.
------------------------------
Date: 1 Apr 2003 04:20:39 -0800
From: David.Hiskiyahu@brinksinc.com (David Hiskiyahu)
Subject: Re: Mail::Sender - comma separated email address lists
Message-Id: <b07846ff.0304010420.b29494f@posting.google.com>
Thanks for the tip about 'Die'.
For a while I escaped the problem by looping, though
I hated to do so - sending messages one-by-one slows
the things down significantly.
I wonder if the error in case of a comma-separated
email address list comes due to some limitations set
in the SMTP server ...
Does anyone know if some SMTP server might reject
address lists?
dwilson@gtemail.net (Douglas Wilson) wrote in message news:<3e864bb1.3049914@news.west.cox.net>...
> On 26 Mar 2003 07:59:38 -0800, David.Hiskiyahu@brinksinc.com (David Hiskiyahu)
> wrote:
>
> >use Mail::Sender;
> >
> > eval {
> > (new Mail::Sender)
> > ->MailMsg({smtp => $server,
> > from => $sendFrom,
> > replyto => $replyTo,
> > to => $sendTo,
> > cc => $sendCC,
> > subject => $sendSubj,
> > msg => $sendMsg })
> > } or die "Mail::Sender error!\n";
>
> You should know that Mail::Sender by default does not die on errors, it
> returns a negative integer error code, so there is no point in eval'ing this.
>
> The correct default error checking method here is:
> unless (ref ( ...insert mail sender methods here...) {
> # There was an error
> }
>
> Sorry, this doesn't help you with your original problem, I don't see any
> thing wrong with your 'To' list.
>
> Cheers,
> -Douglas Wilson
------------------------------
Date: 1 Apr 2003 07:43:07 -0800
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: Match words between two files
Message-Id: <1bff1830.0304010743.1238b098@posting.google.com>
Stephan Bour <sbour@niaid.nih.gov> wrote in message news:<BAA9DF6F.69E4%sbour@niaid.nih.gov>...
> I¹ve looked all over my beginner books and I couldn't find any way to
> compare two files for common words. I have an html file on one side with
> someone¹s last name embedded in the code (not separated by white space). On
> the other side I have a comma-delimited file used as a hash to match the
> last name with a valid email address. Right now I use a fairly inflexible
> regular expression split function to extract the name from the html and then
> match it with the hash key. However, I was wondering whether I could skip
> the split routine altogether by parsing the html file and have it look
> directly in the hash file for a match. Is this possible?
Take a look at one of the HTML parsing classes, HTML::Parser,
HTML::TokeParser or HTML::PullParser. They might be overkill for what
you want though. (Especially if you don't have them installed)
> Thank you,
>
> Stephan.
>
> --
------------------------------
Date: Tue, 01 Apr 2003 15:25:19 GMT
From: <alex@nospamhoopsie.com>
Subject: OO problem with Data::Dumper and IO::Scalar
Message-Id: <ybiia.291610$F1.50672@sccrnsc04>
I'm taking a stab at inheritance with perl and am running into a problem.
I've searched the newsgroups on The Right Way to do inheritance in perl,
and quite honestly I didn't get a very clear answer, but I'm going to
go with an approach that *does* have the parent class name hardwired (at
least for this go around). Anyway, The parent class uses IO::Scalar, and
I'm getting a strange error when trying to dump the object with Data::Dumper
from the calling script.
Here's the test code (two perl module files and one perl script):
========================================
package Foo::Parent;
use strict;
use IO::Scalar;
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $s = {};
bless ($s, $class);
$s->initialize(@_);
return $s;
}
sub initialize {
my $s = shift;
my %args = @_;
$s->{parentKey} = 1;
$s->{handle} = IO::Scalar->new($args{data});
}
1;
========================================
package Foo::Parent::Child;
use strict;
use Foo::Parent;
@Foo::Parent::Child::ISA = ('Foo::Parent');
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $s = Foo::Parent->new(@_);
bless ($s, $class);
$s->initialize(@_);
return $s;
}
sub initialize {
my $s = shift;
$s->{childKey} = 1;
}
1;
========================================
#!/usr/bin/perl
use strict;
use Data::Dumper;
use Foo::Parent::Child;
my $data = 'hello';
my $j = Foo::Parent::Child->new(data => \$data);
print "j:\n", Dumper($j);
1;
========================================
When I run the above script, I get the following error:
Can't locate object method "FETCH" via package "IO::Scalar"
(perhaps you forgot to load "IO::Scalar"?)
at /usr/lib/perl5/5.6.1/i386-linux/Data/Dumper.pm line 150.
Any help would be greatly appreciated. I'm using this version of perl:
This is perl, v5.6.1 built for i386-linux
On a machine with redhat 7.2.
TIA,
--Alex
------------------------------
Date: Tue, 1 Apr 2003 07:38:47 -0500
From: "ravlin" <jhayden@usa.com>
Subject: passing variables to fork()
Message-Id: <sLfia.1$HH2.183@chrome-fe.eng.netapp.com>
Hi all,
Is there a way I can pass a variable to fork, change the value of the
variable in the fork'd process and get the value back?
This example doesn't do what I want it to do:
my $test = "parent";
{
if(! defined(my $pid = fork())) {
die "Cannot fork: $!";
} elsif ($pid) {
# I'm the parent
} else {
print("test is $test\n");
$test = "child";
print("test is $test\n");
exit (0);
}
}
wait;
print("test is $test\n");
Output is:
test is parent
test is child
test is parent
I want the output to be:
test is parent
test is child
test is child
Any idea on how I can do this? I even tried passing the variable as a
reference and it still didn't work.
Thanks a lot for any ideas or suggestions.
Jon
------------------------------
Date: 1 Apr 2003 13:07:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: passing variables to fork()
Message-Id: <b6c2u8$b4n$1@mamenchi.zrz.TU-Berlin.DE>
ravlin <jhayden@usa.com> wrote in comp.lang.perl.misc:
> Hi all,
>
> Is there a way I can pass a variable to fork, change the value of the
> variable in the fork'd process and get the value back?
No. The child process is a *copy* of the parent process. Any changes
to variables the child makes don't affect the copies in the parent,
and vice versa.
[...]
> Any idea on how I can do this? I even tried passing the variable as a
> reference and it still didn't work.
You need some form of inter-process communication for that. See
perldoc perlipc.
Anno
--
--
sub nmax { @$_[ @_] = (); $#$_ }
------------------------------
Date: 01 Apr 2003 14:05:51 +0100
From: brianr@liffe.com
Subject: Re: Perl Debugger : ptkdb
Message-Id: <vty92u9xlc.fsf@liffe.com>
david@tvis.co.uk (zzapper) writes:
> Hi Perlies
>
> I'm just getting used to ptkdb which amongst another things can
> display the contents of an array of hashes just by hovering the mouse
> over it.
>
> Download from V1.108 http://world.std.com/~aep/ptkdb/
>
> But I'm a little concerned that no seems to be updating it; since 01
> Oct 2000
It is now on CPAN. Devel::ptkdb is now at version 1.1084 and dated 28 Nov 2002.
>
> . I also can't much info on how to use it.
There is quite a bit of documentation with the module. Try `perldoc
Devel::ptkdb` when you have installed it.
HTH
--
Brian Raven
[End of diatribe. We now return you to your regularly scheduled
programming...]
-- Larry Wall in Configure from the perl distribution
------------------------------
Date: Tue, 01 Apr 2003 14:05:15 +0100
From: "Richard Gration" <richard@zync.co.uk>
Subject: Re: Perl Interview Questions...
Message-Id: <20030401.140515.260152959.22584@richg.zync>
In article <3E895B38.2070007@oracle.com>, "Nagaraj Hegde"
<Nagaraj.Hegde@oracle.com> wrote:
> Does any one have perl interview question and answer ? Please send it
> to me or give me the location....
>
Good morning Perl, how do you feel about being one of the most widely used
scripting languages in the world?
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
------------------------------
Date: Tue, 1 Apr 2003 07:31:56 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl Interview Questions...
Message-Id: <slrnb8j56c.36b.tadmc@magna.augustmail.com>
Malte Ubl <ubl@schaffhausen.de> wrote:
> Nagaraj Hegde wrote:
> > Subject: Perl Interview Questions...
>> Does any one have perl interview question and answer ? Please send it
>> to me or give me the location....
>
> In your subject you are asking for Perl questions while in your message
> body you are asking for perl questions.
>
> Maybe you should ask for the difference between the two :)
Q: What language is perl written in?
A: C
Q: What language is Perl written in?
A: Perl
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 01 Apr 2003 13:46:39 GMT
From: Steven Smolinski <steven.smolinski@sympatico.ca>
Subject: Re: Perl Interview Questions...
Message-Id: <3Lgia.1916$oA1.351594@news20.bellglobal.com>
Richard Gration <richard@zync.co.uk> wrote:
> "Nagaraj Hegde" <Nagaraj.Hegde@oracle.com> wrote:
>> Does any one have perl interview question and answer ? Please send
>> it to me or give me the location....
>
> Good morning Perl, how do you feel about being one of the most widely
> used scripting languages in the world?
No, the OP specified "perl" interview questions and answers, not "Perl."
How about:
Q. Well, 5.8.0, why should I pick you over, say, 5.6.1?
A. See perldelta.pod.
Steve
--
Steven Smolinski => http://arbiter.ca/
GnuPG Public Key => http://arbiter.ca/steves_public_key.txt
=> or email me with 'auto-key' in the subject.
Key Fingerprint => 08C8 6481 3A7B 2A1C 7C26 A5FC 1A1B 66AB F637 495D
------------------------------
Date: Tue, 01 Apr 2003 15:41:02 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Perl Interview Questions...
Message-Id: <iqiia.20943$gp1.18779@nwrddc02.gnilink.net>
Tad McClellan wrote:
> Q: What language is perl written in?
> A: C
>
> Q: What language is Perl written in?
> A: Perl
Isn't ist more like
A2: English and EBNF
jue
------------------------------
Date: Tue, 01 Apr 2003 11:09:38 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: search a dir for a file
Message-Id: <3e8971f0.281751577@news.cis.dfn.de>
On Mon, 31 Mar 2003 21:28:34 -0500, "h8dnwld"
<noneya@biz.com> wrote:
>I am trying to search a dir for any file that ends in ".txt". would fgrep
>be the way to go? Can I use the same ($, ^ or . ) as I would in unix
>fgrep?
Here are 3 ways:
# General method
opendir DIR, $dir or die "Cannot opendir $dir:$!\n";
my @files = grep /\.txt$/i, readdir DIR;
closedir DIR;
# Shortcut method
my @files = glob ("$dir/*.txt");
# Recursive method
use File::Find;
my @files;
find sub {push @files,$File::Find::name if /\.txt$/i;},$dir;
__END__
--
Regards, Helgi Briem
helgi DOT briem AT decode DOT is
------------------------------
Date: Tue, 01 Apr 2003 07:29:22 -0500
From: "h8dnwld" <noneya@biz.com>
Subject: Re: search a dir for a file
Message-Id: <pan.2003.04.01.12.29.19.522648@biz.com>
On Mon, 31 Mar 2003 21:28:34 +0000, h8dnwld wrote:
> I am trying to search a dir for any file that ends in ".txt". would fgrep
> be the way to go? Can I use the same ($, ^ or . ) as I would in unix
> fgrep?
>
> THANKS
thank you gent, reading the man works
------------------------------
Date: Tue, 1 Apr 2003 08:30:14 -0600
From: Barry Kimelman <barryk2@SPAM-KILLER.mts.net>
Subject: Re: search a dir for a file
Message-Id: <MPG.18f35e6c12461ef9989779@news.mts.net>
[This followup was posted to comp.lang.perl.misc]
In article <pan.2003.04.01.02.28.34.53655@biz.com>, h8dnwld
(noneya@biz.com) says...
> I am trying to search a dir for any file that ends in ".txt". would fgrep
> be the way to go? Can I use the same ($, ^ or . ) as I would in unix
> fgrep?
>
> THANKS
>
Several possibilities :
(1)
open(DIR,"$name_of_directory")
or dir("opendir failed : $!\n");
@entries = readdir DIR;
closedir DIR;
@txt_files = grep /\.txt$/,@entries;
(2)
@txt_files = glob($name_of_directory."/*.txt");
Note : you might want to adjust the error checking and test this in your
system.
--
---------
Barry Kimelman
Winnipeg, Manitoba, Canada
email : bkimelman@hotmail.com
------------------------------
Date: Tue, 1 Apr 2003 14:09:52 -0000
From: "Steve Ferson" <daNOSPAM_beano@hotmail.com>
Subject: Simple Filehandle Seek prob
Message-Id: <Fcgia.409$ha7.71430@newsfep1-win.server.ntli.net>
I have the following bit of code which is supposed to implement a really
basic guestbook.
open (MESSAGE, ">> $file" )|| die "Can't open file: $!";
seek MESSAGE, 0, 0;
print MESSAGE "$input\n\n";
close MESSAGE;
The problem is that $input is added at the END of the file rather than the
beginning as is the intetion. Does anyone know what I'm doing wrong as I
don't understand.
Thanks,
Steve
------------------------------
Date: Tue, 01 Apr 2003 15:30:00 +0200
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: Simple Filehandle Seek prob
Message-Id: <3E899458.2B50F6C9@fujitsu-siemens.com>
Steve Ferson wrote:
> =
> I have the following bit of code which is supposed to implement a reall=
y
> basic guestbook.
> =
> open (MESSAGE, ">> $file" )|| die "Can't open file: $!";
> seek MESSAGE, 0, 0;
> print MESSAGE "$input\n\n";
> close MESSAGE;
> =
> The problem is that $input is added at the END of the file rather than =
the
> beginning as is the intetion. Does anyone know what I'm doing wrong as =
I
> don't understand.
1. You open the file for append, yet want to insert.
2. There is no magic code which will insert data at the beginning of a
file.
See perldoc perlfaq5
"How do I change one line in a file/delete a line in a file/insert a
line in the middle of a file/append to the beginning of a file?"
Also check the archives. This question has been asked n times (for any
n).
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Tue, 1 Apr 2003 07:26:57 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: split map avoid error message
Message-Id: <slrnb8j4t1.36b.tadmc@magna.augustmail.com>
Alexander Stremitzer <stremitz@consultant.com> wrote:
> This was really helpful.
It won't happen again.
[snip TOFU]
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 4800
***************************************