[16775] in Perl-Users-Digest
Perl-Users Digest, Issue: 4187 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 31 09:05:24 2000
Date: Thu, 31 Aug 2000 06:05:11 -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: <967727111-v9-i4187@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 31 Aug 2000 Volume: 9 Number: 4187
Today's topics:
Re: About reading the chinese file. <bill.kemp@wire2.com>
Am I d.u.m.b??? <mrpkahle@dingoblue.net.au>
Re: Am I d.u.m.b??? <baumann@isw.unibe.chwithoutspam>
Am I dumb? <mrpkahle@dingoblue.net.au>
Re: cgi displayed as text <mtaylorlrim@my-deja.com>
Re: Extra ^M in text file <elephant@squirrelgroup.com>
Fat comma quoting [was: Re: Bulk add to a hash.. Thanks (Keith Calvert Ivey)
Re: generate the html doc. (David Wall)
Help !!! (HPUX11+Oracle8+DBD) ishulz@lycosmail.com
Re: Help !!! (HPUX11+Oracle8+DBD) ishulz@lycosmail.com
Re: How get all parameters of cgi-form? (Anthony Peacock)
Re: How get all parameters of cgi-form? <mrpkahle@dingoblue.net.au>
Re: How get all parameters of cgi-form? <lincolnmarr@nospam.europem01.nt.com>
Re: How to read a dir with recursive directories? (Anno Siegel)
Re: Just another silly post. <madings@baladi.bmrb.wisc.edu>
Re: Just another silly post. <rick.delaney@home.com>
Re: Modem communication (/dev/ttyS*) (Michael P. Soulier)
Re: Passing arrays from subroutines. nobull@mail.com
Re: Removing an entry from a text file basingwerk1@my-deja.com
Re: Removing an entry from a text file (Rafael Garcia-Suarez)
Using SDBM_File to compare large files. c_j_marshall@hotmail.com
Re: Using SDBM_File to compare large files. (Anno Siegel)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 31 Aug 2000 11:17:18 +0100
From: "W Kemp" <bill.kemp@wire2.com>
Subject: Re: About reading the chinese file.
Message-Id: <967717245.1858.0.nnrp-03.c3ad6973@news.demon.co.uk>
Lincoln Marr wrote in message <8ol3lg$qb7$1@qnsgh006.europe.nortel.com>...
>This may be completely wrong but don't you just have to change the encoding
>on the browser to traditional chinese character set??
see (4)
>I don't think this is
>a Perl question though....
Neither do I but before finding a better group for this-
1) What encoding is the incoming file in?
2) What encoding do you expect to output to the web page
3) Do you know how to set the encoding at the start of the web page
4) Does the user have the correct font set on their browser
>> But when on the web page, it will show the ÁÙ¤£«Hªº¸Ü,ºô¥D·|© code,
>> Does anyone know how to solve this problems?
>>
>> 1.pl
>> print header();
>> ........
>> open(INFILE, "$filenm") || err("Error on opening files: $!");
>> while (<INFILE>)
>> {
>> print "$_\n";
>> }
>> close(INFILE);
This looks ok as long as the incoming file is in utf-8 or another encoding
that browsers can use.
------------------------------
Date: Thu, 31 Aug 2000 23:59:38 +1000
From: "Phill Kahle" <mrpkahle@dingoblue.net.au>
Subject: Am I d.u.m.b???
Message-Id: <39ae5617$0$26546$7f31c96c@news01.syd.optusnet.com.au>
Can someone please help me. I have wrtien a small quick program to read a
file of the cdrom drive. Now it should be very simple to do but I can't
seem to read anything. It's works fine with the A drive and C: but not the
cdrom. Any answers please?
The error is that the file can't be found but the file is there at the right
locations.
I have a pioneer DVD.
I have win2000.
I have the latest perl.
here is a small example program.
open(IN, "d:\dir1\example.txt") || die "can't open the file";
$a="$a$_" while(<IN>);
------------------------------
Date: Thu, 31 Aug 2000 15:17:52 +0200
From: "Adrian A. Baumann" <baumann@isw.unibe.chwithoutspam>
Subject: Re: Am I d.u.m.b???
Message-Id: <8oll1b$q78$1@news1.sunrise.ch>
One word: Backslashes...
Try it with a forward slash instead.
Phill Kahle <mrpkahle@dingoblue.net.au> wrote in message
news:39ae5617$0$26546$7f31c96c@news01.syd.optusnet.com.au...
> Can someone please help me. I have wrtien a small quick program to read
a
> file of the cdrom drive. Now it should be very simple to do but I can't
> seem to read anything. It's works fine with the A drive and C: but not
the
> cdrom. Any answers please?
>
> The error is that the file can't be found but the file is there at the
right
> locations.
>
> I have a pioneer DVD.
> I have win2000.
> I have the latest perl.
>
> here is a small example program.
>
> open(IN, "d:\dir1\example.txt") || die "can't open the file";
> $a="$a$_" while(<IN>);
>
>
>
>
>
>
------------------------------
Date: Thu, 31 Aug 2000 23:32:16 +1000
From: "Phill Kahle" <mrpkahle@dingoblue.net.au>
Subject: Am I dumb?
Message-Id: <39ae4fac$0$26533$7f31c96c@news01.syd.optusnet.com.au>
Can someone please help me. I have wrtien a small quick program to read a
file of the cdrom drive. Now it should be very simple to do but I can't
seem to read anything. It's works fine with the A drive and C: but not the
cdrom. Any answers please?
The error is that the file can't be found but the file is there at the right
locations.
I have a pioneer DVD.
I have win2000.
I have the latest perl.
here is a small example program.
open(IN, "d:\dir1\example.txt") || die "can't open the file";
$a="$a$_" while(<IN>);
------------------------------
Date: Thu, 31 Aug 2000 12:40:51 GMT
From: Mark <mtaylorlrim@my-deja.com>
Subject: Re: cgi displayed as text
Message-Id: <8oljof$9gk$1@nnrp1.deja.com>
In article <8okqil$de3$1@nnrp1.deja.com>,
hobyah75@my-deja.com wrote:
> I wrote a cgi script on my linux (redhat) server. It runs fine.
>
> I transferred the script to a new linux (unsure of which version)
> server, which I *only* have FTP access to.
>
If it was a permissions problem the server would return a Permissions
Denied error.
Apache can be set to allow cgi on a per directory basis. It sounds to
me like your cgi bin is not set to allow the running of scripts. This
is done in the httpd.conf file, which you have no control over. If his
server is not secured properly you can probably browse around and find
the file and have a look at it. Even if it is in there the server needs
to be restarted before it will take effect.
I considered the possibility that your path to perl on the first line
was incorrect, but if that was so you would get an internal server
error. Verify the path with your administrator anyway.
Apache can also alias to a different script directory. If this was
happening then when you attempted to execute your script it would
return a Page not Found error, so that is probably not the case.
I would write a simple "Hello World" script and place it in your cgi-
bin and simply ask the server administrator to go to the URL. He will
get it going for you and tell you what you are doing wrong. Don't be
afraid to ask.
Mark
--
Please reply to this newsgroup as my Deja mail
is used as a spam catcher only!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 31 Aug 2000 10:34:19 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: Extra ^M in text file
Message-Id: <MPG.1418d07d784aee0898973a@localhost>
nkhan75@hotmail.com <nkhan75@hotmail.com> wrote ..
>I am working with Perl/NT. Every time I create a text file from my
>program, I find a ^M at the end of each line of the file.
>
>Does anyone know why this is happening?
everyone else is yacking on about FTP and UNIX vs Win32 file endings ..
so maybe I'm completely confused here .. but your post says that you're
creating these files from a Perl program
if this is the case .. then the likely cause of this problem is that
you're outputting an extra ^M into your text file
this is correct
open OUTPUT, '>outputfile' or die "Bad open: $!";
print OUTPUT "This line will have one ^M and one ^J on Win32\n";
close OUTPUT or die "Bad close: $!";
this is wrong
open OUTPUT, '>outputfile' or die "Bad open: $!";
print OUTPUT "This line will have two ^Ms and one ^J on Win32\r\n";
close OUTPUT or die "Bad close: $!";
this is also correct (but only for Win32 text files)
open OUTPUT, '>outputfile' or die "Bad open: $!";
binmode OUTPUT;
print OUTPUT "This line will have one ^Ms and one ^J on Win32\r\n";
close OUTPUT or die "Bad close: $!";
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Thu, 31 Aug 2000 12:07:05 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Fat comma quoting [was: Re: Bulk add to a hash.. Thanks for the help!]
Message-Id: <39b1489b.42756582@news.newsguy.com>
Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
> LR> Even that isn't true. Try 1x => 'foo' for example.
>
> LR> Perhaps /^[^\W\d]\w*\z/ .
>
>and of course there is another special case. a leading - is allowed in
>the tokens (can't call it a bareword then) autoquoted by =>. this comes
>from the common use of -foo as a key/attribute in sub calls.
I thought it was the other way around: the common use of -foo in
sub calls came from the fact that you could do it. And a
bareword is still a bareword if it has an operator in front of
it.
Anyway, it's not a special dispensation for unary -. The =>
operator quotes barewords before it even when they have other
operators applied to them. These produce no complaints from
strict or -w:
print 'foo' . bar => 123;
print length baz => 'abc';
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: 31 Aug 2000 09:03:21 -0400
From: darkon@one.net (David Wall)
Subject: Re: generate the html doc.
Message-Id: <8FA15AAF2darkononenet@206.112.192.118>
chaptera@hotmail.com (Tom) wrote in <39AE2778.6842E1F7@hotmail.com>:
>$js<<END
This should be
$js=<<END;
See perlfaq4, "Why don't my <<HERE documents work?"
perldoc -q "here doc"
--
David Wall
darkon@one.net
------------------------------
Date: Thu, 31 Aug 2000 11:12:26 GMT
From: ishulz@lycosmail.com
Subject: Help !!! (HPUX11+Oracle8+DBD)
Message-Id: <8oleih$3ja$1@nnrp1.deja.com>
I'd like to know is it possible to mix above mentioned components in
one box?
I ran throw all threads in the forum concerning subj, and it seems for
me that this is a big problem.
I've installed gcc 2.95.2, perl 5.6.0, Oracle 8.1.6, DBI-1.1.14 on HPUX
11.0 without any problems. But DBD refused to be compiled (or more
exactly linked):
________
LD_RUN_PATH="" ld -o blib/arch/auto/DBD/Oracle/Oracle.sl -b -
L/usr/local/lib Oracle.o dbdimp.o oci7.o oci8.o -L/RAID01/app/oracle/p
roduct/8.1.6/lib/ -L/RAID01/app/oracle/product/8.1.6/rdbms/lib -Wl,+s -
Wl,+n /RAID01/app/oracle/product/8.1.6/lib/nautab.o /RAID0
1/app/oracle/product/8.1.6/lib/naeet.o /RAID01/app/oracle/product/8.1.6/
lib/naect.o /RAID01/app/oracle/product/8.1.6/lib/naedhs.o `c
at /RAID01/app/oracle/product/8.1.6/lib/ldflags` -lnsgr8 -lnzjs8 -
ln8 -lnl8 -lnro8 `cat /RAID01/app/oracle/product/8.1.6/lib/ldf
lags` -lnsgr8 -lnzjs8 -ln8 -lnl8 -lclient8 -lvsn8 -lwtc8 -
lcommon8 -lgeneric8 -lmm -lnls8 -lcore8 -lnls8 -lcore8 -lnls8 `cat
/RAID01/app/oracle/product/8.1.6/lib/ldflags` -lnsgr8 -lnzjs8 -ln8 -
lnl8 -lnro8 `cat /RAID01/app/oracle/product/8.1.6/lib/ldflag
s` -lnsgr8 -lnzjs8 -ln8 -lnl8 -lclient8 -lvsn8 -lwtc8 -lcommon8 -
lgeneric8 -ltrace8 -lnls8 -lcore8 -lnls8 -lcore8 -lnls8 -lc
lient8 -lvsn8 -lwtc8 -lcommon8 -lgeneric8 -lnls8 -lcore8 -lnls8 -
lcore8 -lnls8 -lm /RAID01/app/oracle/product/8.1.6/rdbms/li
b/kpudfo.o `cat /RAID01/app/oracle/product/8.1.6/lib/sysliblist`
ld: Unrecognized argument: -Wl,+s
ld: Usage: ld flags... files...
____
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 31 Aug 2000 11:53:58 GMT
From: ishulz@lycosmail.com
Subject: Re: Help !!! (HPUX11+Oracle8+DBD)
Message-Id: <8olh0f$67a$1@nnrp1.deja.com>
In article <8oleih$3ja$1@nnrp1.deja.com>,
ishulz@lycosmail.com wrote:
> I'd like to know is it possible to mix above mentioned components in
> one box?
Right now I've tried to rebuild perl,DBI and DBD as static. perl and
DBI againg reinstalled fine (and tested ok). DBD was compiled and
linked as well, but when I tried to test it it died:
-----------------------------------------------------
gcc -L/usr/local/lib -o perl -O ./perlmain.o
blib/arch/auto/DBD/Oracle/Oracle.a /opt/perl5/lib/site_perl/5.6.0/PA-
RISC2.0/
auto/DBI/DBI.a /opt/perl5/lib/5.6.0/PA-
RISC2.0/auto/re/re.a /opt/perl5/lib/5.6.0/PA-
RISC2.0/auto/attrs/attrs.a /opt/perl5/lib/5.6
.0/PA-RISC2.0/auto/Sys/Syslog/Syslog.a /opt/perl5/lib/5.6.0/PA-
RISC2.0/auto/Sys/Hostname/Hostname.a /opt/perl5/lib/5.6.0/PA-RISC2.
0/auto/Socket/Socket.a /opt/perl5/lib/5.6.0/PA-
RISC2.0/auto/SDBM_File/SDBM_File.a /opt/perl5/lib/5.6.0/PA-
RISC2.0/auto/POSIX/POSIX
.a /opt/perl5/lib/5.6.0/PA-
RISC2.0/auto/Opcode/Opcode.a /opt/perl5/lib/5.6.0/PA-
RISC2.0/auto/ODBM_File/ODBM_File.a /opt/perl5/lib
/5.6.0/PA-RISC2.0/auto/NDBM_File/NDBM_File.a /opt/perl5/lib/5.6.0/PA-
RISC2.0/auto/IPC/SysV/SysV.a /opt/perl5/lib/5.6.0/PA-RISC2.0/
auto/IO/IO.a /opt/perl5/lib/5.6.0/PA-
RISC2.0/auto/File/Glob/Glob.a /opt/perl5/lib/5.6.0/PA-
RISC2.0/auto/Fcntl/Fcntl.a /opt/perl5/
lib/5.6.0/PA-
RISC2.0/auto/DynaLoader/DynaLoader.a /opt/perl5/lib/5.6.0/PA-
RISC2.0/auto/Devel/Peek/Peek.a /opt/perl5/lib/5.6.0/PA-R
ISC2.0/auto/Devel/DProf/DProf.a /opt/perl5/lib/5.6.0/PA-
RISC2.0/auto/Data/Dumper/Dumper.a /opt/perl5/lib/5.6.0/PA-
RISC2.0/auto/Byt
eLoader/ByteLoader.a /opt/perl5/lib/5.6.0/PA-
RISC2.0/auto/B/B.a /opt/perl5/lib/5.6.0/PA-RISC2.0/CORE/libperl.a `cat
blib/arch/auto/
DBD/Oracle/extralibs.all` -lnsl -lnm -lndbm -ldld -lm -lc -lndir -
lcrypt -lsec
/usr/bin/ld: Unsatisfied symbols:
naecta (data)
naectc (data)
naecti (data)
naectn (data)
naeetnu (data)
naeeta (data)
naeetc (data)
naeeti (data)
naeetn (data)
nautab (data)
ACSSVC_new (code)
naedhsk (code)
naedhpk (code)
naedhp (code)
nautabnum (data)
naeetcu (data)
naeetau (data)
appc_c_version (code)
collect2: ld returned 1 exit status
*** Error exit code 1
Stop.
------
It seems that I need some library. Or not?
Help, please.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 31 Aug 2000 12:05:39 GMT
From: a.peacock@chime.ucl.ac.uk (Anthony Peacock)
Subject: Re: How get all parameters of cgi-form?
Message-Id: <8olhmj$fje$1@uns-a.ucl.ac.uk>
In article <8ol57u$2979$1@news.itfs.nsk.su>, paul@pco.iis.nsk.su says...
>
>Hello,
>
>It's strange but I could not find the way to do it. I need array of all
>parameters of cgi form.
>I tried $q->param, but it did not work.
>
>I use 'post' method.
>
>Thanks for help
[Lets see if I can be the first to post these questions:-)]
We need more information.
What do you mean by "it did not work"?
Do you get an error message? How do you know it didn't work?
Please post a small example of your actual code that illustrates the problem.
------------------------------
Date: Thu, 31 Aug 2000 23:45:24 +1000
From: "Phill Kahle" <mrpkahle@dingoblue.net.au>
Subject: Re: How get all parameters of cgi-form?
Message-Id: <39ae52d8$0$26529$7f31c96c@news01.syd.optusnet.com.au>
It's easy just to use cgi-lib.pm
So include it in your program with the require command and then use a read
phrase routine in the cgi-lib to throw all the prams into a hash.
"Paul Dortman" <paul@pco.iis.nsk.su> wrote in message
news:8ol57u$2979$1@news.itfs.nsk.su...
> Hello,
>
> It's strange but I could not find the way to do it. I need array of all
> parameters of cgi form.
> I tried $q->param, but it did not work.
>
> I use 'post' method.
>
> Thanks for help
>
>
> Paul
>
>
------------------------------
Date: Thu, 31 Aug 2000 14:55:05 +0200
From: "Lincoln Marr" <lincolnmarr@nospam.europem01.nt.com>
Subject: Re: How get all parameters of cgi-form?
Message-Id: <8olkj3$58q$1@qnsgh006.europe.nortel.com>
I think you'll find it's cgi-lib.pl and it was originally built for Perl
4.... the norm these days is to use CGI.pm which is a lot easier, if it's
too heavy duty for what you want there's a lighter CGI module too (can't
remember it's name though).
Just make sure that in your Perl script you have the html with all the input
fields names set to the parameter names. But this is more a question for
comp.infosystems.www.authoring.cgi really....
"Phill Kahle" <mrpkahle@dingoblue.net.au> wrote in message
news:39ae52d8$0$26529$7f31c96c@news01.syd.optusnet.com.au...
> It's easy just to use cgi-lib.pm
>
> So include it in your program with the require command and then use a read
> phrase routine in the cgi-lib to throw all the prams into a hash.
>
> "Paul Dortman" <paul@pco.iis.nsk.su> wrote in message
> news:8ol57u$2979$1@news.itfs.nsk.su...
> > Hello,
> >
> > It's strange but I could not find the way to do it. I need array of all
> > parameters of cgi form.
> > I tried $q->param, but it did not work.
> >
> > I use 'post' method.
> >
> > Thanks for help
> >
> >
> > Paul
> >
> >
>
>
------------------------------
Date: 31 Aug 2000 12:26:19 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to read a dir with recursive directories?
Message-Id: <8olitb$l3b$1@lublin.zrz.tu-berlin.de>
Abigail <abigail@foad.org> wrote in comp.lang.perl.misc:
>Rodrigo Cortés (roco3d@pmail.net) wrote on MMDLVII September MCMXCIII in
><URL:news:5Mlr5.8365$gi.115631@maule>:
>{} What is the faster way to do this and list the archives?
>
>
>Faster than what?
...and what is a recursive directory? Sounds scary.
Anno
------------------------------
Date: 31 Aug 2000 10:36:48 GMT
From: Steve Mading <madings@baladi.bmrb.wisc.edu>
Subject: Re: Just another silly post.
Message-Id: <8olcg0$8is$2@news.doit.wisc.edu>
Rick Delaney <rick.delaney@home.com> wrote:
: Steve Mading wrote:
:>
:> That's a command-line switch. I was referring to a regular-expression
:> switch
: And I was referring to an equally relevant switch.
Relevant? How? The topic at hand was how to make the
regular epression match '\n' as a normal character instead
of as $.
------------------------------
Date: Thu, 31 Aug 2000 12:15:39 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Just another silly post.
Message-Id: <39AE4ED6.3229C707@home.com>
Steve Mading wrote:
>
> Rick Delaney <rick.delaney@home.com> wrote:
>
> : And I was referring to an equally relevant switch.
>
> Relevant? How? The topic at hand was how to make the
> regular epression match '\n' as a normal character instead
> of as $.
You said earlier:
> Perl regex's can be told to match $ to end-of-string with a switch.
My switch brings us as close to that goal as your switch.
[Clue: neither the /s nor the /m modifiers make $ match end-of-string.]
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: Thu, 31 Aug 2000 12:30:36 GMT
From: michael.soulier@home.com (Michael P. Soulier)
Subject: Re: Modem communication (/dev/ttyS*)
Message-Id: <slrn8qsjvd.1q0.michael.soulier@localhost.localdomain>
In article <8ol2is$n22$1@nnrp1.deja.com>, ambrosa@hsgerardo.org wrote:
>
>Which is the best way (using alarm to manage the timeout) to "speak"
>with /dev/ttyS* ??
I have the feeling that you want the lower-level C open() function. So,
either do this in C, or use sysopen().
perldoc -f sysopen
man perlopentut
Cheers,
Mike
------------------------------
Date: 31 Aug 2000 12:11:56 +0100
From: nobull@mail.com
Subject: Re: Passing arrays from subroutines.
Message-Id: <u9ya1dwupv.fsf@wcl-l.bham.ac.uk>
"Carter" <carter@aodinc.com> writes:
> ... I am a little confused on referencing arrays,
> and would like to make sure I am passing the array from the subroutine
> correctly.
"Correctly" is not uniquely defined. Your approach is one possible
approach. Without more context it is impossible to say if it is the
best.
> my (@stuff, $reference);
> my $var=5;
> ($reference, $var) = &get_data($var);
> @stuff = @$reference;
> sub get_data {
> my $value = $_[0];
> my @data = ('yellow tang', 'clown trigger', 'cleaner wrasse');
> print "Main sent me: ",$value++,"\n";
> return(\@data, $value);
> }
> --end script--
Rather than saying --end script-- say __END__. That way if we pipe
your post into the Perl interpreter we don't need to worry about the
end.
You should also get out of the habit of putting & on fuction calls.
Putting a & on a fuction call means that you want to disregard the
prototype if there is one. If there is no prototype then this has no
effect but one day you may try to use a function that has got a
prototype and then you'll have problems.
> Is this right?
The disadvantage of your approach is that it involves copying the
array.
Here's just one of many other alternatives:
my (@stuff);
my $var=5;
get_data(\@stuff,\$var);
sub get_data {
my ($data,$value) = @_;
@$data = ('yellow tang', 'clown trigger', 'cleaner wrasse');
print "Main sent me: ",$$value++,"\n";
}
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 31 Aug 2000 11:14:03 GMT
From: basingwerk1@my-deja.com
Subject: Re: Removing an entry from a text file
Message-Id: <8olelh$3k0$1@nnrp1.deja.com>
Here's a working version of the code. The changes were in the match
expression, to use any whitespace, and the use of the numeric compare
instead of a string compare (!= instead of ne). That way, you don't
care about the trailing \n. Yes, for a huge file, it's bad to pull it
into memory. Better to read a line at a time and write to a tmp file,
rename at the end. But for normal files, this is OK.
Steve
$this_id = 2;
open (ADDD, "peoplelist.txt") or die ("Unable open mirror file");
@openfile = <ADDD>;
close (ADDD);
open (NDL, ">peoplelist2222.txt");
$check='NO';
foreach $line (@openfile)
{
$theline = $line;
($person, $id) = split(/\s+/, $theline);
if (($this_id != $id) or ($check eq 'YES')){
print NDL "$line";
}
else{
$check = "YES";
}
}
In article <slrn8qrvam.a86.rgarciasuarez@rafael.kazibao.net>,
rgarciasuarez@free.fr (Rafael Garcia-Suarez) wrote:
> Dave Labbett wrote in comp.lang.perl.misc:
> >I'm a PERL beginner so please bear with me if this is a simple
question.
> >
> >I've set up a PERL program which lets me log 2 pieces of data (Name
and ID)
> >to a tab separated text file.
> >
> >Example of how the text file looks :
> >
> >Dave Labbett 12345
> >John Smith 23456
> >Tom Jones 24680
> >
> >It works fine and I can read and display the data in this text file
straight
> >to a web page no problem.
> >
> >However, from an ADMIN script, I want to be able to delete an entry
from
> >this text file based on the ID number. I type in this ID and the
script
> >reads through the text file, line by line until it gets a match. It
should
> >then delete this line from the file - leaving all the rest intact.
> >
> >Trouble is - I just cannot get it to work at all - the relevant
piece of
> >code is:
> >
> >$this_id = ($input{'userid'});
> > open (ADDD, "$info_dir/peoplelist.txt") or &error("Unable open
mirror
> >file");
> > @openfile = <ADDD>;
> > close (ADDD);
> >
> > open (NDL, ">$info_dir/peoplelist.txt");
>
> You should check the return value of this open too. opens do fail.
This
> happens.
>
> > $check='NO';
> > foreach $line (@openfile) {
> > $theline = $line;
> > ($person, $id) = split(/\t/, $theline);
>
> Here is the error. $id contains a trailing "\n".
> Include the line
> chomp $line;
> before the split.
> The variable $theline is unneccessary: split does not modify its
> argument.
>
> > if (($this_id ne $id) or ($check eq 'YES')){
> > print NDL "$line";
>
> Unneccessary quotes around $line. But if you chomp'd $line, you'll
have to
> print NDL "$line\n";
>
> > }
> > else{
> > $check = "YES";
> > }
> >}
> >
> >Any advice anyone can give would be greatly appreciated!
>
> Other advices:
>
> If peoplelist.txt is a large file, don't read it in memory; open a
file
> peoplelist.new where you put the new contents, then unlink
> peoplelist.txt and rename peoplelist.new to peoplelist.txt.
>
> It is perhaps better style to use 0 and 1 instead of YES and NO for
> $check.
>
> --
> Rafael Garcia-Suarez
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 31 Aug 2000 11:28:39 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Removing an entry from a text file
Message-Id: <slrn8qsgg6.auu.rgarciasuarez@rafael.kazibao.net>
basingwerk1@my-deja.com wrote in comp.lang.perl.misc:
>Here's a working version of the code. The changes were in the match
>expression, to use any whitespace, and the use of the numeric compare
>instead of a string compare (!= instead of ne). That way, you don't
>care about the trailing \n. Yes, for a huge file, it's bad to pull it
>into memory. Better to read a line at a time and write to a tmp file,
>rename at the end. But for normal files, this is OK.
>
>$this_id = 2;
>
>open (ADDD, "peoplelist.txt") or die ("Unable open mirror file");
>@openfile = <ADDD>;
>close (ADDD);
>
>open (NDL, ">peoplelist2222.txt");
>$check='NO';
>foreach $line (@openfile)
>{
> $theline = $line;
> ($person, $id) = split(/\s+/, $theline);
> if (($this_id != $id) or ($check eq 'YES')){
> print NDL "$line";
> }
> else{
> $check = "YES";
> }
>}
You said that the file contained lines like
Dave Labbett 12345
When you split /\s+/ such lines, $id will have the value 'Labbett'.
Not what you want.
--
Rafael Garcia-Suarez
------------------------------
Date: Thu, 31 Aug 2000 12:17:15 GMT
From: c_j_marshall@hotmail.com
Subject: Using SDBM_File to compare large files.
Message-Id: <8olibt$81h$1@nnrp1.deja.com>
Hi,
Apologies if this is a duplicate - original seems to have got lost.
I'm trying to reconcile two 90MB size files and was hoping to use DBM to
access them nicely (as they are handily keyed on a single unique
integer) rather than attempt to pull them into huge hashes in memory.
I was hoping that the code below would open a simple text file:
$cat testfile
key1 val1
key2 val2
key3 val3
and pull it into a hash - which could then be used to random access the
file.
I've read through all the documentation I can find (O'reillys cookbook,
adv perl, camel3, perldoc perltie) but can't get this working. It can
write a new file OK - when I run the code below I vaguely expected it to
list the existing file contents, then list them again with two new
entries.
Instead it never lists the originals, lists the new entries and creates
a testfile.pag and testfile.dir for me.
Have I got completely the wrong end of the stick in how to use this
functionality ? If not - I can't find any mention of what the delimiter
should be to separate the key/value pairs in the source file.
Cheers
Chris
#!/usr/local/bin/perl
use Fcntl;
use SDBM_File;
use diagnostics;
tie %hash, "SDBM_File", "testfile", O_RDWR|O_CREAT, 0666
or warn "Can't open testfile:\n\t$!\n";
# read all existing values
foreach $k (sort keys %hash){
print "k:$k\tv:$hash{$k}\n";
}
# add two new ones
$hash{"newkey1"}="newval1";
$hash{"newkey2"}="newval2";
# read all values again
foreach $k (sort keys %hash){
print "k:$k\tv:$hash{$k}\n";
}
print "done\n";
---
results:
$test.pl
k:newkey1 v:newval1
k:newkey2 v:newval2
done
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 31 Aug 2000 13:02:05 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Using SDBM_File to compare large files.
Message-Id: <8oll0d$l62$1@lublin.zrz.tu-berlin.de>
<c_j_marshall@hotmail.com> wrote in comp.lang.perl.misc:
>Hi,
>
>Apologies if this is a duplicate - original seems to have got lost.
>
>I'm trying to reconcile two 90MB size files and was hoping to use DBM to
>access them nicely (as they are handily keyed on a single unique
>integer) rather than attempt to pull them into huge hashes in memory.
>
>I was hoping that the code below would open a simple text file:
> $cat testfile
> key1 val1
> key2 val2
> key3 val3
>
>and pull it into a hash - which could then be used to random access the
>file.
No, that isn't the way it works. SDBM_File uses a special format to
store keyed information on disk. In fact, when you tie a hash to
"testfile", SDBM expects (or creates) two disk files "testfile.dir"
and "testfile.pag", one for the keys and the other for the data.
>I've read through all the documentation I can find (O'reillys cookbook,
>adv perl, camel3, perldoc perltie) but can't get this working. It can
>write a new file OK - when I run the code below I vaguely expected it to
>list the existing file contents, then list them again with two new
>entries.
>
>Instead it never lists the originals, lists the new entries and creates
>a testfile.pag and testfile.dir for me.
There you go. It completely ignores your file named "testfile".
>Have I got completely the wrong end of the stick in how to use this
>functionality ? If not - I can't find any mention of what the delimiter
>should be to separate the key/value pairs in the source file.
That's because the source file format isn't (usually) described at
all. It's considered an internal feature.
The only exception I can think of is DB_File (built on Berkeley DB),
which has a DB_RECNO feature. This ties a (possibly existing) plain
file to an array (not hash), so that each line of the file appears
to be one array element.
You may be able to use that feature when you combine it with a hash
that associates each key with the corresponding record number in the
file. That way you can randomly hop around your data based on
keys.
Anno
------------------------------
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 4187
**************************************