[10552] in Perl-Users-Digest
Perl-Users Digest, Issue: 4144 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 3 23:07:34 1998
Date: Tue, 3 Nov 98 20:00:17 -0800
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, 3 Nov 1998 Volume: 8 Number: 4144
Today's topics:
delete a file under win95 (!) <avitala@macs.biu.ac.il>
Re: delete a file under win95 (!) (Sam Holden)
Echoing multi-line text to the DOS shell (UnixDBA)
Re: Echoing multi-line text to the DOS shell (Sam Holden)
Re: find and replace <bill@fccj.org>
Re: i just find a whatsnew cgi script <nsurfer@bellsouth.net>
Re: illegitimate data types ? (Patrick Timmins)
Re: illegitimate data types ? (Sam Holden)
Re: Not to start a language war but.. (Dave Kirby)
Re: Not to start a language war but.. (Dave Kirby)
Re: Not to start a language war but.. (Thomas Andrews)
perl5 make fails buckyjune@my-dejanews.com
Re: Reading multiple lines (Tad McClellan)
Re: Replacing chracters in a variable (Tad McClellan)
Re: Replacing chracters in a variable (Darren Greer)
Re: uninstalling modules <aravind@genome.wi.mit.edu>
Re: uninstalling modules <mpersico@erols.com>
Re: uninstalling modules <mpersico@erols.com>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 3 Nov 1998 19:16:09 +0200
From: "Avshi Avital" <avitala@macs.biu.ac.il>
Subject: delete a file under win95 (!)
Message-Id: <71ndt1$ikk$1@cnn.cc.biu.ac.il>
what could be more simple then that?!
well, i tried:
unlink 'file_name'
system('del file_name');
and even:
exec('del file_name');
but the file stays. so what's the trick?
thanx,
--
Avshalom Avital
Information Retrieval Laboratory
Bar-Ilan University, Israel
avitala@macs.biu.ac.il
------------------------------
Date: 4 Nov 1998 02:23:07 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: delete a file under win95 (!)
Message-Id: <slrn73vekb.1bn.sholden@pgrad.cs.usyd.edu.au>
On Tue, 3 Nov 1998 19:16:09 +0200, Avshi Avital <avitala@macs.biu.ac.il> wrote:
>what could be more simple then that?!
>well, i tried:
>
>unlink 'file_name'
Works for me...
>system('del file_name');
>
>and even:
>
>exec('del file_name');
If those two don't work then it is not a perl problem...
Either the file_name is wrong, the current directory is wrong, or the
permissions are wrong...
You could try doing some error checking...
--
Sam
Just don't create a file called -rf. :-)
--Larry Wall
------------------------------
Date: 4 Nov 1998 03:30:38 GMT
From: unixdba@aol.com (UnixDBA)
Subject: Echoing multi-line text to the DOS shell
Message-Id: <19981103223038.23081.00003433@ng35.aol.com>
I am trying to do this without resorting to any of the following DOS mainstays:
batch files or temporary files.
I need to write ***ONE*** ***PERL*** ***SCRIPT*** to do execute a command in
Sybase's isql utility.
In UNIX I can write the script, mysql.pl, which contains the following text:
################################################################
#!/usr/local/bin/perl
# Initialize an array to contain the output
# of the following SQL command.
# Note that the call to isql is within this Perl script.
@output = `isql -whatever << EOF
sp_who
go
EOF`;
# Print the contents of the array.
print @output;
################################################################
This script is a marvel of simplicity, and upon its structure I can write
killer SQL scripts, using Perl's capabilities to extend the limited
functionality of the Sybase Interactive SQL utility.
My question is simple.
How would I do this in DOS? Or, how do I echo multi-line text at the prompt in
the DOS shell.
Keywords: *ONE* *PERL* *SCRIPT* *NO* *BATCH* *FILES* *NO* *INTERMEDIATE*
*FILES*
------------------------------
Date: 4 Nov 1998 03:35:48 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Echoing multi-line text to the DOS shell
Message-Id: <slrn73visk.4m8.sholden@pgrad.cs.usyd.edu.au>
On 4 Nov 1998 03:30:38 GMT, UnixDBA <unixdba@aol.com> wrote:
>
>My question is simple.
>
>How would I do this in DOS? Or, how do I echo multi-line text at the prompt in
>the DOS shell.
That would be a DOS question then... As opposed to a perl question...
--
Sam
Simple rule: include files should never include include files.
--Rob Pike
------------------------------
Date: Tue, 03 Nov 1998 21:55:07 -0500
From: Bill Jones <bill@fccj.org>
Subject: Re: find and replace
Message-Id: <363FC20B.4F729CC8@fccj.org>
mikej wrote:
>
> Hi everyone,
>
> Im trying to open an html file and replace parts of it. I basically open
> the file and try to do a substitute command on keywords already in the
> file, which should get replaced. Say I want to change where it says
> <!--replace me--> to <!--it worked--> in an html page. I call this
> subroutine:
>
> sub replace_text {
>
> open (MYFILEHANDLE, ">>files/index.html");
>
> while ($content = <MYFILEHANDLE> {
> $content =~ s/<!--replace me-->/<!--it worked-->/i;
> }
>
> close MYFILEHANDLE;
>
> }
>
> It is supposed to go through my html file and replace where it says
> "<!--replace me-->" with "<!--it worked-->", but it doesn't do anything.
>
>
>
> Anyone know what is wrong with it? Any examples of find and replace
> scripts that are easy to understand would be a good help too. Thanks for
> your help.
>
>
> -Mike
>
>
Hmmmm, try something like this:
#!/usr/bin/perl -w
use strict;
#
# html Anchor Tag Maker - Changes course reference TAGs in HTML Tags...
#
# htmlAnchorTagMaker.pl - v0.01 (Alpha)
#
# written by Sneex, FCCJ Webmaster Oct. 4th, 1998 @ 17:00
#
# Note: This script changes all tags at one time...
my @tags = qw{ACG AST CCJ COP ECO ENL FAD GER IDS LIS MET
MUG MVK ORI PHT REL
SPN WST ADV ATF CDA COT EDF ENS FFP GLY IND LIT MGF
MUH MVO OST PHY
RET STA ZOO AER ATT CET CPO EDG ESL FIL GRA INR MAC
MHF MUL MVP PCB
PHZ RMI SUR AMH AVM CGS CRW EDP EST FIN HFT ISC MAE
MKA MUM MVS PEL
PLA RTE SYG AML BAN CHD CTE EEC ETC FOS HIS ISS MAN
MLT MUN MVV PEM
POS RTV TAR ANT BCN CHI DAA EET ETD FRE HLP ITA MAP
MMC MUO MVW PEN
PSC RUS TAX APA BCT CHM DEH EHD ETG FSS HSC JOU MAR
MRE MUR NUR PEO
PSY SLS THE ARH BOT CIS DEP EME ETI GEA HUM LAH MAS
MTB MUS OCB PET
QMB SOP TPA ART BSC CJD DES EMS ETM GEB HUN LEI MAT
MUC MUT OCE PGY
REA SPA TPP ASC BUL CJT DIE EUH GEO HUS LIN MCB MUE
MVB ORH PHI ENC
REE SPC TRA};
my $target;
my $tag;
my @targets;
push @targets, @ARGV;
# $_ = shift(@targets);
while(1) {
$target = shift(@targets);
#print "Reading $target ";
open (OFILE, "$target") or die "\n\nCan't open $target: $!\n\n";
# Let's try this:
$/ = ".\n";
while (<OFILE>)
{
#print "Writing $target ";
open (NFILE, ">>../$target") or die "\n\nCan't open ../$target:
$!\n\n";
foreach $tag(@tags) {
# The text that needs replacing:
my $oChunk = qq{$tag};
# New Anchor Tag...
#my $iChunk = (split(/ /, $oChunk))[1];
my $iChunk = $oChunk;
# With this text:
my $nChunk = qq{<a href=/catalog/current/cd/$iChunk/>$iChunk</a>};
#print "Looking at $tag ";
s{$oChunk}{$nChunk}g;
}
print NFILE;
}
close (NFILE) or die "\n\nCan't close ../$target: $!\n\n";
close (OFILE) or die "\n\nCan't close $target: $!\n\n";
# print "...\n";
last unless (@targets);
next;
}
# Ref:
#$x++ if $_ =~ /(?:\W|\b)$oChunk(?:\w|\b)/; # Same as \bCOP\b ?
HTH,
-Sneex- :]
________________________________________________________________________
Bill Jones | FCCJ Webmaster | x3089 | http://webmaster.fccj.org:81
------------------------------------------------------------------------
__ _ RedHat 5.1 Manhatten
/ /(_)_ __ _ ___ __ http://www.apache.org
/ / | | '_ \| | | \ \/ / http://www.redhat.com
/ /__| | | | | |_| |> < http://www.perl.com
\____/_|_| |_|\__,_/_/\_\ http://www.gimp.org
------------------------------
Date: Wed, 04 Nov 1998 02:25:31 GMT
From: Steve Miles <nsurfer@bellsouth.net>
Subject: Re: i just find a whatsnew cgi script
Message-Id: <363FB967.68CFB66F@bellsouth.net>
Try www.cgi-resources.com
cutebaby@my-dejanews.com wrote:
> someboby have the whatsnew(new) perl cgi script
>
> plz tell me whhere to get
>
> , because my homepage need it
>
> need your help ~
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 04 Nov 1998 03:43:38 GMT
From: ptimmins@netserv.unmc.edu (Patrick Timmins)
Subject: Re: illegitimate data types ?
Message-Id: <71oiha$cmf$1@nnrp1.dejanews.com>
In article <71nupd$9qv17@mercury.adc.com>,
bhilton@tsg.adc.com (Brand Hilton) wrote:
> In article <71np6v$5ri$1@nnrp1.dejanews.com>,
> Patrick Timmins <ptimmins@netserv.unmc.edu> wrote:
> >In article <71nef7$ls0$1@nnrp1.dejanews.com>,
> > mgrabens@my-dejanews.com wrote:
> >
> >> In the following code snigglet, does this create an illegitimate data
> >> type?
> >> $myhash{key1} = 'Person';
> >> $myhash{key1}{fname} = 'Mike';
> >> $myhash{key1}{lname} = 'Grabenstein';
> >> $myhash{key2} = 'Class';
> >> ... etc ...
> >
> >Bastard data types? Never! Both parents are listed on the birth
> >certificate under the surname 'perldoc': (Mrs. perlref perldoc and
> >Mr. perldsc perldoc).
>
> Are you sure about that? I think what he's referring to is that fact
> that he's set $myhash{key1} to a string, and then in the next line he
> sets it to a hash reference, and Perl keeps both of them, so that if
> you "print $myhash{key1}", you get "Person", and if you
> "print $myhash{key1}{fname}" you get "Mike".
>
> Pretty freaky if you ask me. Neither dumpvar.pl nor Data::Dumper
> recognize the hash reference... they stop with "Person".
>
> Anybody from p5p wanna give an authoritative reply?
I don't know, but I do this all the time ... I hope I haven't been
getting away with something ... :(
My understanding is that we have a hash name %myhash, with key-value
pairs, just like normal. So when you say
$myhash{key1} = 'Person';
you've just place another pair in the hash with a key of 'key1' and
a value of 'Person'. Now when you say
$myhash{key1}{fname} = 'Mike';
Perl instantly creates a reference to another hash. This new hash
is %{ $myhash{key1} } as opposed to %myhash . This new hash has a
a first key-value pair of 'Person' for the key, and a *reference*
to the hash:
{'fname' => 'Mike',
'lname' => 'Grabenstein',
'etc_key' => 'etc_value'}
for the value.
Basically, the 'value' in the first hash becomes the 'key' to the new
referenced hash. The value for $myhash{key1} *is* still 'Person'. But
by then saying $myhash{key1}{fname}, you've instantly made 'Person'
a reference to a new hash as well.
At least this is the way I understand it :)
Patrick Timmins
$monger{Omaha}[0]
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 4 Nov 1998 03:54:14 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: illegitimate data types ?
Message-Id: <slrn73vjv6.5ep.sholden@pgrad.cs.usyd.edu.au>
On Wed, 04 Nov 1998 03:43:38 GMT, Patrick Timmins <ptimmins@netserv.unmc.edu>
wrote:
<snip>
>I don't know, but I do this all the time ... I hope I haven't been
>getting away with something ... :(
And if you had been using 'usr strict' you would have been informed what
was really going on, and not have to go back and change all that code now...
--
Sam
compiling kernels is what I do most, so they do tend to stick to the
cache ;) --Linus Torvalds
------------------------------
Date: Mon, 02 Nov 1998 21:27:44 GMT
From: dkirby@see.sig.for.addr (Dave Kirby)
Subject: Re: Not to start a language war but..
Message-Id: <363e1112.7628513@read.news.global.net.uk>
On Mon, 02 Nov 1998 09:56:43 +0000, Matt Sergeant
<msergeant@ndirect.co.uk_NOSPAM> wrote:
>Dave Kirby wrote:
>>
>> >: * better cross platform support. Since I work in Windows/NT this is a
>> >: biggie.
>> > [snip]
>> >: and with PythonWin I can create COM objects, do Active
>> >: Scripting, access the windows API & MFC etc.
>> >
>> > And there goes your praised "truely cross-platform" argument. :-)
>> >
>> > Seriously, you really should check out the Win32::* modules.
>>
>> I've just had a look at the latest CPAN listing. I dont see any
>> mention of COM, ActiveX, Active Scripting, calling the C or MFC API
>> etc. With PythonWin you can write a full blown Windows application
>> using all of these.
>
>That's all in Libwin32. It's all there. There are several options
>(choice is a good thing) for writing COM objects in Perl. You can access
>COM objects using Win32::OLE, you can access any API using Win32::API,
>you can write GUI's using Win32::GUI (easier to use than MFC).
>ActiveScripting is there with PerlScript.
OK, I stand corrected. I looked at CPAN.html and it says:
| libwin32 - A bundle of Win32 modules that build under the latest
| version of Perl. It includes all of the ActiveState extensions plus these
| third-party modules: Clipboard,, Console, Internet, Shortcut, Sound,
| AdminMisc, ODBC, Pipe. No binaries are included; you'll need either
| Visual C++ 4.x+ or Borland C++ 5.0x+ to build these modules.
No mention of OLE, ActiveScripting etc. I suggest that if you want
people to use it you tell them its there.
>
>With Perl, you can write a full blown windows application using all of
>these.
Are there many people out there actually doing this? I havn't heard of
any Windows apps being created in perl, but then I havn't been
looking. Judging from postings to c.l.py there seems to be a fairly
high proportion of of python users working in Windows, far higher that
the proportion of perl users (at least from what I recall from when I
regularly read c.l.pl a couple of years ago - the balance may have
shifted since then).
I am curious to know what the proportions of Windows to Unix users are
for each language. I am not sure how you would accurately measure it
- perhaps by the relative number of downloads of the Windows binaries
to the source versions. Obviously this would give a somewhat skewed
answer since some Windows users will download the source as well as or
instead of the binaries, but it would be a good first approximation.
not-trying-to-make-a-point-just-curious-ly y'rs
Dave K
--------------------------------------------------
All great ideas start as heresy and end as dogma.
dkirby@ <-figure this out, spambots!
bigfoot. My opinions are my own,
com but I'm willing to share.
------------------------------
Date: Mon, 02 Nov 1998 21:27:45 GMT
From: dkirby@see.sig.for.addr (Dave Kirby)
Subject: Re: Not to start a language war but..
Message-Id: <363f183a.9460846@read.news.global.net.uk>
On Mon, 02 Nov 1998 10:29:03 -0500, John Porter <jdporter@min.net>
wrote:
>Dave Kirby wrote:
>>
>> OK, "disagree" was a poor chice of words - "got it wrong" would have
>> been better. Surely you can see why the fact that
>>
>> sub Widget::new { bless {} }
>> is wrong but
>> sub Widget::new { bless {}, shift }
>> is right is not exactly obvious
>
>Again, poor choice of words. s/wrong/not preferable/; s/right/preferable/.
>
As far as I can tell from reading perltoot.pod, the right/preferable
version is necessary for inheritance to work properly. If I read it
right the first version will work ok until you (or someone else)
derives from the class at which point it will fall over. To my mind
that makes the first version wrong.
>
>> If someone who has little or no experience of perl looks at a module
>> file it is not obvious at all that a class is being declared.
>
>Well, considering that a class *isn't being declared*, I can't easily
>argue with you.
>It's the creation of objects which has primacy in perl, not the declaration
>of classes. The notion of a class in perl is very fluid, very dynamic.
According to the docs the package that the reference is being blessed
into is the class of that object, so you are still defining a class.
>
>
>> I would
>> go as far as saying that a total novice would not have a hope in hell
>> of understanding what is going on without a careful reading of the
>> docs.
>
>We have other code for you perl novices to sample, if you don't like
>the OO flavor.
>
>
>> With python it is immediately apparent that a class is being
>> created even to someone who has never seen the language before.
>
>Only because the construction is similar to other languages with which
>they already have familiarity. A good analogy can be drawn to human
>languages.
It is also because in python the keyword that defines the class is not
hidden away in the middle of a function. Even an experienced perl
hacker would have to scan through the text of a package to find out if
it is a class or not. Not having this vital piece of information at
the place that the package is declared unncessarily increases the
cognitive effort of understanding the code.
>
>
>> I used perl for years for the creation of various utilities and I cant
>> remember ever using classes in production code - it simply wasnt in my
>> perl mindset.
>
>I think that's a feature of perl.
Exactly what I've been saying - perl discourages OO programming.
>
>> This may have been partly a result of starting with
>> perl4 so never getting into the habit, but also because the process is
>> unnecessarily complicated.
>
>The process is not complicated at all. Just different.
>
>> For most of that time I was programming in
>> C++ as my main language so was familiar with the benefits of OO
>> techniques, and had played around with classes when I first got perl5
>> so I knew how to do it, but when it came to the crunch I would still
>> write perl procedurally.
>
>Often when I start a program (or component thereof) I write it
>procedurally at first; and soon enough it cries out to be OO.
>So I make it OO. It's never hard. Maybe because I'm not predisposed
>to think it's hard.
>
>John Porter
It doesnt need to be hard, just a little mental effort is enough to
make a difference to the way you use a language. The Worf hypothesis
states that thought follows language - the way you think about a
problem is dictated by the language you are thinking in. While this is
debatable for human languages I find it is definitely true for
computer languages (for me at least). When I am thinking in perl I
think procedurally and if absolutely necessary translate it into OO
form later, since it takes more mental effort - which is what you
imply you do. In python I am far more likely to think in OO terms from
the start since it is more natural in that language. My experience is
that it makes me a better programmer in python than I am in perl.
Dave K
--------------------------------------------------
All great ideas start as heresy and end as dogma.
dkirby@ <-figure this out, spambots!
bigfoot. My opinions are my own,
com but I'm willing to share.
------------------------------
Date: 3 Nov 1998 19:14:33 -0800
From: thomaso@best.com (Thomas Andrews)
Subject: Re: Not to start a language war but..
Message-Id: <71ogqp$19s$1@shell3.ba.best.com>
In article <363f183a.9460846@read.news.global.net.uk>,
>
>Exactly what I've been saying - perl discourages OO programming.
>
I essentially agree with this.
> When I am thinking in perl I think procedurally and if absolutely
> necessary translate it into OO form later
That seems to be your mistake - I never think in the implementation
language unless I have to. I start thinking implementation after
I have an OO design. I can implement that design in some languages
more easily than other, but perl only requires a little bit of
effort, compared to "C" for instance.
--
Thomas Andrews thomasoa@yahoo.com http://www.best.com/~thomaso/
"Show me somebody who is always smiling, always cheerful, always
optimistic, and I will show you somebody who hasn't the faintest
idea what the heck is really going on." - Mike Royko
------------------------------
Date: Wed, 04 Nov 1998 03:25:14 GMT
From: buckyjune@my-dejanews.com
Subject: perl5 make fails
Message-Id: <71oheq$bak$1@nnrp1.dejanews.com>
I am attempting to install perl 5.00502 into my user dir (srs/perl) so that I
can later install the LWP bundle. (no root access, no admin help, on my own
here). On sun4-solaris.
I have specified a non-default path to my user dir for the installation:
sh Configure -Dprefix=/services/www/htdocs/srs/perl
I am not aware that I need to edit any other files. I used all defaults during
Configure except that I had to create ../srs/perl/bin to proceed w/ Configure.
So far so good, until near the end of the make command. It looks like
Config.pm cannot be found, althought it does exist in ../srs/perl/lib/:
(Current working directory is /services/www/htdocs/srs/perl) --- % make
...<snip>... CCCMD = cc -B/usr/ccs/bin/ -DPERL_CORE -c -I/usr/local/include
-I/opt /gnu/include -O rm -f libperl.a ar rcu libperl.a perl.o malloc.o gv.o
toke.o perly.o op.o regcomp.o dump.o util. o mg.o byterun.o hv.o av.o run.o
pp_hot.o sv.o pp.o scope.o pp_ctl.o pp_sys.o do op.o doio.o regexec.o taint.o
deb.o universal.o globals.o perlio.o cc -B/usr/ccs/bin/ -L/usr/local/lib
-L/opt/gnu/lib -o miniperl miniperlmain.o l ibperl.a -lsocket -lnsl -lgdbm
-ldb -ldl -lm -lc -lcrypt ./miniperl -w -Ilib -MExporter -e 0 ||
/usr/ccs/bin/make minitest Can't open perl script "-e": Permission denied
make: Warning: Both `makefile' and `Makefile' exist Current working directory
/services/www/htdocs/srs/perl You may see some irrelevant test failures if
you have been unable to build lib/Config.pm. cd t && (rm -f perl;
/usr/local/bin/ln -s ../miniperl perl) \ && ./perl TEST base/*.t comp/*.t
cmd/*.t io/*.t op/*.t pragma/*.t </dev /tty base/cond.........ok
base/if...........ok base/lex..........ok base/pat..........ok
base/rs...........ok base/term.........Can't open /dev/null. at base/term.t
line 45. FAILED at test 6 Failed a basic test--cannot continue. *** Error
code 2 (ignored) ./miniperl configpm tmp sh mv-if-diff tmp lib/Config.pm
./miniperl -Ilib pod/pod2html.PL Extracting pod2html (with variable
substitutions) ./miniperl -Ilib pod/pod2latex.PL Extracting pod2latex (with
variable substitutions) ./miniperl -Ilib pod/pod2man.PL Extracting pod2man
(with variable substitutions) ./miniperl -Ilib pod/pod2text.PL Extracting
pod2text (with variable substitutions) AutoSplitting perl library ./miniperl
-Ilib -e 'use AutoSplit; \ autosplit_lib_modules(@ARGV)' lib/*.pm lib/*/*.pm
Can't open perl script "-e": Permission denied *** Error code 13 make: Fatal
error: Command failed for target `preplibrary' 262.0u 69.0s 29:34 18% 0+0k
0+0io 0pf+0w
--- The error "Can't open perl script "-e": Permission denied" is puzzling as
is the message" "You may see some irrelevant test failures if you have been
unable to build lib/Config.pm."
I can't tell what is irrelevant and what is not! Seems like everything is
relevant in the Unix world.
Anyone care to set me straight on the path to success? Don't be afraid to not
skimp on the details ;)
1024K thanks...
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 3 Nov 1998 21:29:15 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Reading multiple lines
Message-Id: <bmho17.47b.ln@flash.net>
Alistair Calder (webmaster@topproducer.com) wrote:
: Okay, I read the perlvar man page, and my dim glimmer of PERL knowledge
: tells me that $/ will convert the entire file into one line, am I correct?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
No, it does not change the file contents in any way.
It changes how perl _reads_ the file though.
It reads it all at once.
It is still as many lines as it was before, but all of the
lines are contained in the single scalar variable.
: If so, then my:
: foreach $item(@NEWS){
^^^^^
: [read this line and parse it for info]
: }
: won't work because the whole file is one continuous line.
True enough that it won't work, because it accesses an *array*
and the data in not in an array anymore.
Now it is in a scalar.
: If this is the
: case, I'm as far behind as when I started.
I think you are closer to a solution than when you started.
: When I mentioned earlier that I would like to read the whole chunk of data,
: I meant that I want to read the three lines that refer to:
: Line 1: The anchor and linked text
: Line 2: The by-line, or description of the previous line
: Line 3: the <BR><BR> line that delimits each news item.
: in a group, not the entire file.
Oh.
Well, if you want to get multiple lines, you have two
(or three) choices:
1) slurp the whole file, then pluck out what you want
2) read line by line and "build up" the multiline part that
you are interested in.
3) maybe you can define $/ in such a way that it grabs the
multiple lines of interest
If there are *always* two <br>s on a line by themselves,
and the two <br>s *always* indicate the end of an "interesting"
part, then you can:
$/ = "<br><br>\n";
while (<>) {
print;
}
: Now, forgive me if I am being naive, but the $/ solution doesn't seem to get
: me any further ahead. Am I wrong? Can I treat the whole document as one
: line,
You are overly concerned with the concept of a "line".
Lines are not "special". We humans find it convenient
to think of lines, so Perl lets us manipulate lines.
You have a series of bytes. Some of those bytes happen to
be newline characters, but perl doesn't care that us humans
like to put a special interpretation on the meaning of
an ASCII 10 (decimal) character. To Perl, it is just a
byte like any other.
You cannot treat the whole document as one line unless it
*is* one line.
You can, however, treat the whole document as a single
value (scalar).
: but still extract the proper 3 lines that I require for my local
: document?
So (if I remember correctly, and I'm not sure that I do) your
question was "how to deal with the 'record' as a whole?"
#3 above would be best, but it is subject to many restrictions.
We don't have enough info to know if that is a viable approach.
I'll guess that you want to pull out three parts from each
"record": 1) the URL
2) the contents of the anchor element
3) the "subject"
Maybe this will help:
--------------------------------------------
#!/usr/bin/perl -w
{
undef $/;
$_ = <DATA>; # slurp the whole file
}
while ( m#<a\s+href="([^"]+)"\s*>(.+?)</a>.*?<br>([^\n]+)#gs ) {
$url = $1;
$anchor = $2;
$subject = $3;
print "url: $url\nanchor: $anchor\nsubject: $subject\n\n";
}
__DATA__
<a href="story.asp?ID=11236">Chase Manhattan gets real</a>
<br>Mortgage Corp. division has real time loan status reports
<br><br>
<a href="another.story.asp?ID=11236">another Chase Manhattan gets real</a>
<br>another Mortgage Corp. division has real time loan status reports
<br><br>
--------------------------------------------
But I must once again point out that this is a dirty hack that
will easily break (ie. it wouldn't take much for it to stop working).
The only real way to parse HTML is to *parse* HTML. Throwing
pattern matches at HTML is a low quality approach...
Good luck anyway!
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 3 Nov 1998 21:35:58 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Replacing chracters in a variable
Message-Id: <u2io17.47b.ln@flash.net>
Nico v Leeuwen (nicovl@hotmail.com) wrote:
: I have been puzzeled with a question I have a variable and this
: varaible might have some carridge returns in it I want my program to
: replace the CRT's
^^^
^^^
Man, I hate it when those pesky Cathode Ray Tubes get
into my variables... ;-)
: in the variable
tr/\r//d; # delete carriage returns (UNTESTED)
: with a HTML tag.
I dunno what that means. Sorry.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 04 Nov 1998 03:26:32 GMT
From: drgreer@qtiworld.com (Darren Greer)
Subject: Re: Replacing chracters in a variable
Message-Id: <363fc834.629230655@news.qgraph.com>
Im am by no means a perl expert, but you might want to do some reading
on regular expressions and the s/// command.
So:
$htmltag = '<br>';
$newvar = ($oldvar =~ s/\n/$htmltag/g);
may work for you......im sure someone will post a followup pointing
out any errors I may have in my code. But the general idea is there.
Darren
On Wed, 04 Nov 1998 00:29:21 GMT, nicovl@hotmail.com (Nico v Leeuwen)
wrote:
>I have been puzzeled with a question I have a variable and this
>varaible might have some carridge returns in it I want my program to
>replace the CRT's in the variable with a HTML tag. What code could I
>best use?
------------------------------
Date: Tue, 03 Nov 1998 10:52:01 -0500
From: Aravind Subramanian <aravind@genome.wi.mit.edu>
Subject: Re: uninstalling modules
Message-Id: <363F26A0.8025F350@genome.wi.mit.edu>
[Courtesy cc to poster]
Just a reminder to ask if you could kindly post the script.
Thanks,
aravind
"Matthew O. Persico" wrote:
> [ cc to poster ]
>
> I have a script that reads the .packlist for a module, figures out what
> files are part of it and deletes them. It is at work and it is Saturday
> now. I'll mail to you Monday, post Monday night.
>
> Aravind Subramanian wrote:
> >
> > I am trying to set up a web page that provides the following
> > functionality:
> >
> > List currently installed CPAN modules
> > Install a CPAN module
> > Upgrade a CPAN module
> > Uninstall a CPAN module
> >
> > CPAN.pm is of great help in doing most of this. Except, I can't figure
> > out how to uninstall a perl module (either using CPAN.pm or by some
> > other means).
> >
> > Any suggestions?
> >
> > Thanks,
> > aravind
>
> --
> Matthew O. Persico
> Nothing even remotely clever at the moment.
------------------------------
Date: Tue, 03 Nov 1998 22:44:37 -0500
From: "Matthew O. Persico" <mpersico@erols.com>
To: Matt Knecht <hex@voicenet.com>, "Charles J. Leslie" <cjl@loopie.net>
Subject: Re: uninstalling modules
Message-Id: <363FCDA5.313A3A8D@erols.com>
This is a multi-part message in MIME format.
--------------2026BACC638749573FAB1837
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
[cc'd to others]
One teeny weeny shell scrip to find .packlist files.
One unInstall.pl script to uninstall a module.
Flame away. If it's any good, I'll send it to p5p.
--
Matthew O. Persico
Nothing even remotely clever at the moment.
--------------2026BACC638749573FAB1837
Content-Type: application/x-sh;
name="find_packlist.sh"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="find_packlist.sh"
find $HOME/local -name .packlist
--------------2026BACC638749573FAB1837
Content-Type: application/x-perl;
name="unInstall.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="unInstall.pl"
#!/usr/local/bin/perl
## unInstall.pl
## Generates and uninstall script from an installation log
##
## Inits
##
use strict;
## - when debugging: use diagnostics;
use integer; ## Unless you really are doing floating point math.
##
## Published perl modules
##
use Carp qw (carp croak confess);
use Data::Dumper;
use File::Basename;
use IO::File;
##
## Standard globals for identification
##
my $SCRIPT_SPEC = $0;
my $SCRIPT = basename($0);
my $VERSION = '1.04';
##
## Command line usage statement
##
my $usage = <<"usageEOS";
usage: $SCRIPT_SPEC options | packlist [packlist ...]
Options are:
--[no]doit : execute the removal commands directly.
The negation simply prints the commands
instead.
--[no]doit and --script are mutually exclusive.
--script : write shell remove commands to a file named
'modulename'.uninstall.
This is the default action.
--[no]doit and --script are mutually exclusive.
--rmflags flags : optional flags to pass to the rm command
used in the script created by --script. Do
not specify the -; it will be added.
--version : identify this version of $SCRIPT_SPEC and exit.
--help|-h : print this message and exit
usageEOS
##
## Process options
##
use Getopt::Long;
Getopt::Long::config(qw (no_ignore_case no_auto_abbrev));
my %optionCtrl=();
croak "Invalid option(s)\n$usage\n"
unless GetOptions(\%optionCtrl,
qw(doit!
rmflags=s
script
version
help|h));
## Help and version. The assignments shut up the otherwise useful
## diagnostics.
if (defined($optionCtrl{'help'})) {
croak "$usage\n";
} else {
$optionCtrl{'help'} = "";
}
if (defined($optionCtrl{'version'})) {
croak "Version $VERSION\n";
} else {
$optionCtrl{'version'} = "";
}
if (! defined($optionCtrl{'doit'}) && ! defined($optionCtrl{script})) {
print "Defaulting to creating uninstallation scripts\n";
$optionCtrl{script} = 1;
}
if (defined($optionCtrl{'doit'}) && defined($optionCtrl{script})) {
croak "Cannot specify --[no]doit and --script.\n $usage\n";
}
my $rmCmd = undef;
if (defined($optionCtrl{'doit'})) {
$rmCmd = "unlink";
} else {
$rmCmd = "rm " . ($optionCtrl{rmflags} ? "-$optionCtrl{rmflags}" : "");
}
##
## Process args
##
not $ARGV[0] and die $usage;
##
## main
##
## File handles
my $ih = new IO::File;
## File text
my @lines =();
my $packlist = undef;
for $packlist (@ARGV) {
## Figure the module name
my $modname = dirname($packlist);
$modname =~ s/^.*auto\///;
$modname =~ s/\//::/g;
## Open the pack list
my $pl = new IO::File;
$pl->open("< $packlist") or die "Could not open $packlist for read; $!";
## Create the commands
my $cmd = undef;
while (<$pl>) {
$cmd .= "$rmCmd $_"; #no NL, already there
}
$pl->close();
## Now write it or do it
if ($optionCtrl{'script'}) {
## Open the script
my $script = "$modname.uninstall";
my $oh = new IO::File;
$oh->open("> $script") or die "Could not open $script for write; $!";
print $oh <<EOSCRIPT
#!/bin/sh
## $script
## Uninstalls all the files installed
## as noted in $packlist
## Module $modname
set -x
$cmd
EOSCRIPT
;
$oh->close();
chmod 0755, $script;
print "Wrote $script\n";
}
if ($optionCtrl{'doit'}) {
eval $cmd;
}
}
--------------2026BACC638749573FAB1837--
------------------------------
Date: Tue, 03 Nov 1998 22:52:03 -0500
From: "Matthew O. Persico" <mpersico@erols.com>
To: Matt Knecht <hex@voicenet.com>, "Charles J. Leslie" <cjl@loopie.net>
Subject: Re: uninstalling modules
Message-Id: <363FCF63.E55675E2@erols.com>
This is a multi-part message in MIME format.
--------------1067639B4693673A9C6EAAD9
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
[cc'd to others]
One teeny weeny shell scrip to find .packlist files.
One unInstall.pl script to uninstall a module.
Flame away. If it's any good, I'll send it to p5p.
--
Matthew O. Persico
Nothing even remotely clever at the moment.
--------------1067639B4693673A9C6EAAD9
Content-Type: application/x-sh;
name="find_packlist.sh"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="find_packlist.sh"
find $HOME/local -name .packlist
--------------1067639B4693673A9C6EAAD9
Content-Type: application/x-perl;
name="unInstall.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="unInstall.pl"
#!/usr/local/bin/perl
## unInstall.pl
## Generates and uninstall script from an installation log
##
## Inits
##
use strict;
## - when debugging: use diagnostics;
use integer; ## Unless you really are doing floating point math.
##
## Published perl modules
##
use Carp qw (carp croak confess);
use Data::Dumper;
use File::Basename;
use IO::File;
##
## Standard globals for identification
##
my $SCRIPT_SPEC = $0;
my $SCRIPT = basename($0);
my $VERSION = '1.04';
##
## Command line usage statement
##
my $usage = <<"usageEOS";
usage: $SCRIPT_SPEC options | packlist [packlist ...]
Options are:
--[no]doit : execute the removal commands directly.
The negation simply prints the commands
instead.
--[no]doit and --script are mutually exclusive.
--script : write shell remove commands to a file named
'modulename'.uninstall.
This is the default action.
--[no]doit and --script are mutually exclusive.
--rmflags flags : optional flags to pass to the rm command
used in the script created by --script. Do
not specify the -; it will be added.
--version : identify this version of $SCRIPT_SPEC and exit.
--help|-h : print this message and exit
usageEOS
##
## Process options
##
use Getopt::Long;
Getopt::Long::config(qw (no_ignore_case no_auto_abbrev));
my %optionCtrl=();
croak "Invalid option(s)\n$usage\n"
unless GetOptions(\%optionCtrl,
qw(doit!
rmflags=s
script
version
help|h));
## Help and version. The assignments shut up the otherwise useful
## diagnostics.
if (defined($optionCtrl{'help'})) {
croak "$usage\n";
} else {
$optionCtrl{'help'} = "";
}
if (defined($optionCtrl{'version'})) {
croak "Version $VERSION\n";
} else {
$optionCtrl{'version'} = "";
}
if (! defined($optionCtrl{'doit'}) && ! defined($optionCtrl{script})) {
print "Defaulting to creating uninstallation scripts\n";
$optionCtrl{script} = 1;
}
if (defined($optionCtrl{'doit'}) && defined($optionCtrl{script})) {
croak "Cannot specify --[no]doit and --script.\n $usage\n";
}
my $rmCmd = undef;
if (defined($optionCtrl{'doit'})) {
$rmCmd = "unlink";
} else {
$rmCmd = "rm " . ($optionCtrl{rmflags} ? "-$optionCtrl{rmflags}" : "");
}
##
## Process args
##
not $ARGV[0] and die $usage;
##
## main
##
## File handles
my $ih = new IO::File;
## File text
my @lines =();
my $packlist = undef;
for $packlist (@ARGV) {
## Figure the module name
my $modname = dirname($packlist);
$modname =~ s/^.*auto\///;
$modname =~ s/\//::/g;
## Open the pack list
my $pl = new IO::File;
$pl->open("< $packlist") or die "Could not open $packlist for read; $!";
## Create the commands
my $cmd = undef;
while (<$pl>) {
$cmd .= "$rmCmd $_"; #no NL, already there
}
$pl->close();
## Now write it or do it
if ($optionCtrl{'script'}) {
## Open the script
my $script = "$modname.uninstall";
my $oh = new IO::File;
$oh->open("> $script") or die "Could not open $script for write; $!";
print $oh <<EOSCRIPT
#!/bin/sh
## $script
## Uninstalls all the files installed
## as noted in $packlist
## Module $modname
set -x
$cmd
EOSCRIPT
;
$oh->close();
chmod 0755, $script;
print "Wrote $script\n";
}
if ($optionCtrl{'doit'}) {
eval $cmd;
}
}
--------------1067639B4693673A9C6EAAD9--
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 4144
**************************************