[11212] in Perl-Users-Digest
Perl-Users Digest, Issue: 4812 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 3 02:07:24 1999
Date: Tue, 2 Feb 99 23:00:18 -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, 2 Feb 1999 Volume: 8 Number: 4812
Today's topics:
Re: (((((((((( XXX PASSWORDS ))))))))))))))))) <ebohlman@netcom.com>
Re: advertising script problem <elst.fels@nospam.ping.be>
Re: alternative perl NG for newbies? (Abigail)
Re: are regular expression rationaly designed ? (Ronald J Kimball)
Re: Can you launch a background process from web page? <Robbin.Brahms@trw.com>
Can't coerce array into hash (Bill Moseley)
Re: Checking links <ebohlman@netcom.com>
Re: Filtering... (Ronald J Kimball)
Re: flock not working <eugene@snailgem.org>
Re: grep and a variable jimbob4334@my-dejanews.com
Re: Help me with this small script <ebohlman@netcom.com>
Re: help with last modified <jdf@pobox.com>
Re: locking/linking files - HELP <eugene@snailgem.org>
Re: newbie having trouble with concatination <aqumsieh@matrox.com>
Re: Perl bug on search patterns? (Ronald J Kimball)
Re: Perl bug on search patterns? <uri@home.sysarch.com>
Re: perlscript with ASP (Martien Verbruggen)
Re: read an html from a url <eugene@snailgem.org>
Re: Statistics for comp.lang.perl.misc (Ronald J Kimball)
Re: Statistics for comp.lang.perl.misc (Bill Moseley)
Re: Stopping a foreach loop (Kevin Reid)
Re: tie, hash problem (Ronald J Kimball)
Re: tie, hash problem <jdf@pobox.com>
Re: web load testing code (Martin Vorlaender)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 3 Feb 1999 05:29:21 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: (((((((((( XXX PASSWORDS )))))))))))))))))
Message-Id: <ebohlmanF6KCKx.8In@netcom.com>
Best Passwords to sex pages <haslawww@friko7.onet.pl> wrote:
: 100 % working FREE passwords to best SEX pages
: *********** YOU HAVE to CHECK it !!!!!!!!!! **************
One wonders if the jerk who decided to include c.l.p.m in his crosspost
realized that in Perl, this reads "You have to check it NOT!"
------------------------------
Date: Wed, 3 Feb 1999 07:34:34 +0100
From: "myname@mydomain.com" <elst.fels@nospam.ping.be>
Subject: Re: advertising script problem
Message-Id: <798qjm$hjk$1@news3.Belgium.EU.net>
I asked a question relating to Perl, I didn't ask to write a script only
what are your idea's
to handle such a script.
If the subject of my script was random image generation then you would have
no problem.
Please read the question before you say it wasn't perl related.
OK, I wasn't very polite but look at the facts before you complain.
Thank you,
Peter
Daniel Grisinger heeft geschreven in bericht ...
>"myname@mydomain.com" <elst.fels@nospam.ping.be> writes:
>
>> Yeah good answer, but that wasn't the question was it ?!
>
>You asked a question that isn't related to perl on a perl newsgroup,
>what did you expect?
>
>> Don't be a smartass and let me try to figure this out OK ?
>
>This sentence doesn't appear to have any communicative value. Perhaps
>you'd like to rephrase it into something sensible.
>
>> If I only wanted one banner I wouldn't have asked the freaking question
!!!
>
>Generally speaking, we aren't here to hand out complete applications
>to just anyone who asks. I'll make an exception to get you to go
>away, though. This isn't complete code, but it should get you going
>in the right direction. This returns banner0 50% of the time, banner1
>30% of the time, and banner2 and banner3 10% of the time each.
>
> $banner{$_} = 'banner0.gif' for 0..4;
> $banner{$_} = 'banner1.gif' for 5..7;
> $banner{$_} = 'banner2.gif' for 8;
> $banner{$_} = 'banner3.gif' for 9;
>
> my $random_banner = $banner {int(rand(scalar keys %banner))};
>
>dgris
>--
>Daniel Grisinger dgris@moiraine.dimensional.com
>perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print
>m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'
------------------------------
Date: 3 Feb 1999 04:38:29 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: alternative perl NG for newbies?
Message-Id: <798js5$6b$1@client2.news.psi.net>
Andrew Fry (andrewf@beausys.demon.co.uk) wrote on MCMLXXXI September
MCMXCIII in <URL:news:OxisJAACj3t2EwbQ@beausys.demon.co.uk>:
$$
$$ As I have already said, take this to its logical conclusion and
$$ one could, with some justification, answer 'RTFM' to 99.9% of all
$$ questions.
That certainly isn't true. (See your point c).
$$ This does rather presume that...
$$ (a) newbies know what documentation exists, and know their way around it
If you want to know how the 'ls' command works, you type 'man ls'.
If you want to know how the 'tar' command workds, you type 'man tar'.
If you want to know how the 'cp' command works, you type 'man cp'.
If you want to know how the 'telnet' command works, you type 'man telnet'.
Guess what you have to type to learn more about Perl?
$$ (b) newbies have all the time in the world to read documentation
Oh. Right. They are execused from reading the documentation, cause their
time is so valueble. Wasting time of hundreds or thousands of people
reading their question doesn't matter?
$$ (c) the documentation will tell them precisely what they need to know
$$ (Come know ... anyone who knows technical documentation knows that
$$ that often isnt the case!)
Then they should ask a questions to clearify the documentation. Like,
"the documentation says "Foo bar", but what does that mean?".
$$ (d) reading the numerous Perl books isnt enough
Then they should ask questions to clearify the books.
$$ It may irritate (some of) the experts who use this NG when newbies
$$ post question which are so trivial and obvious and "uninteresting"
$$ (...to quote one of the many condescending replies to myself a while
$$ back) ... but I have to say that I am EQUALLY irritated by a response
$$ which says nothing more that 'RTFM' (...especially when accompanied
$$ by a hint of sarcasm).
$$ I say: if you dont have anything more useful to say than this, then
$$ DONT BOTHER SAYING ANYTHING!
That doesn't help, does it? RTFM points someone to the manual, saying
"what you ask is in the manual". Being silent doesn't help the person
asking the question.
Abigail
--
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'
------------------------------
Date: Wed, 3 Feb 1999 01:04:05 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: are regular expression rationaly designed ?
Message-Id: <1dmmibe.biwuxz181ywn4N@bay1-89.quincy.ziplink.net>
<olivier_pelletier@my-dejanews.com> wrote:
> Subject: are regular expression rationaly designed ?
They were, up until perl5.005. ;-)
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Tue, 02 Feb 1999 22:39:05 -0500
From: Robbin <Robbin.Brahms@trw.com>
Subject: Re: Can you launch a background process from web page?
Message-Id: <36B7C4D9.FF41A44D@trw.com>
Greg Ward wrote:
> Robbin <Robbin.Brahms@trw.com> wrote:
> > This is a multi-part message in MIME format.
> > --------------C5C6748D6F4EBA5719DB3FED
>
> Please don't do this. USENET is a plain ASCII text medium; let's keep
> it that way.
>
I'm sorry for the blunder, it was late at night and the news server i usually
use was not available.
>
> Also, posting the same message three times is not very nice. Careful!
>
> > I'm somewhat new to Perl and was wonder if someone has a sample script and
> > willing to share that will start a client application from a web page, so
> > that the client
> > app will run in the background and bring up it's own gui.
> >
> > like if wanted to start emacs off a web page, or the clock or calendar on
> > Solaris desktop.
>
> I don't, no, but it should be pretty easy to do with fork and exec. Try
> reading the fine documentation: 'perldoc -f fork', 'perldoc -f exec',
> 'perldoc perlipc'. Of course, you need to be running on a REAL
> operating system to use fork. ;-)
>
> Greg
Does Solaris or a flavor of Unix count? I did mention that in the original
post.
>
>
> --
> Greg Ward - software developer gward@cnri.reston.va.us
> Corporation for National Research Initiatives
> 1895 Preston White Drive voice: +1-703-620-8990 x287
> Reston, Virginia, USA 20191-5434 fax: +1-703-620-0913
------------------------------
Date: Tue, 2 Feb 1999 22:16:04 -0800
From: moseley@best.com (Bill Moseley)
Subject: Can't coerce array into hash
Message-Id: <MPG.1121897cbf539e4198969b@nntp1.ba.best.com>
Here's the error message:
[Tue Feb 2 20:53:20 1999] admin5.cgi: Can't coerce array into hash at
(eval 23) line 23.
I finally found if I commented out this line:
$Location_Rec->{-LABELS} = \@text_labels; # <--- this is it
the error goes away. (And that's line 654, not anywhere close to line 23
reported in the error). See code listing below.
Now I can replace the line with these and the error goes away (except my
code is then broken, or course).
$Location_Rec->{-LABELSx} = \@text_labels; # this works, must be the
# key '-LABELS'?
$Location_Rec->{-LABELS} = 'hello'; # Nope, this works.
$Location_Rec->{LABELS} = \@text_labels; # And this works.
Quoting '-LABELS' doesn't make a difference, either. And
$Location_Rec->{-LABELS} doesn't exist until this assignment.
Other examples:
my @x;
$Location_Rec->{-LABELS} = \@x; # doesn't work
my %x;
$Location_Rec->{-LABELS} = \%x; # does work.
I can use a different key, but after a couple of hours messing with it
I'm a bit curious. I wondered if someone might see the problem right
away.
- Any ideas what's causing this problem?
- What is that error message, and why is it telling me line 23?
- I'm using Active State's Perl, if that makes a difference.
For what it's worth, here's the subroutine. I'm basically building two
aligned arrays for a pull down list on a HTML form.
Sorry for posting so much code, but I wanted to show as much of the
story as I can. And I'm lost on this problem.
There's a sample hash structure below that explains $Location_Rec, and
some sample code that makes it run, but not with the error.. of course.
I couldn't make it produce the error outside of the real program.
#--------------- build_locations_labels ----------------------
sub build_locations_labels {
my %tmp;
# build a temp hash of location key => location name for sorting
foreach (keys %{ $Location_Rec->{'TIED_HASH'} } ) {
if (load_DBM_record( $Location_Rec, $_ )) {
$tmp{ $_ } = $Location_Rec->{'name'};
}
}
# create a sorted list of the keys
my @locations = sort {
lc( $tmp{ $a } ) cmp lc( $tmp{ $b } )
} keys %tmp;
# create a list of the names that align with the keys
my @text_labels = map { $tmp{$_} } @locations;
$Location_Rec->{-LABELS} = \@text_labels; # <--- this is it
$Location_Rec->{-VALUES} = \@locations;
$Location_Rec->{ALL} = \%tmp;
}
# -- This reads a record from a DBM, and splits it into
# Named fields.
sub load_DBM_record {
my ($ref,$key ) = @_;
return 0 unless $key;
# reference to an array of field names
my $fields_ref = $ref->{'FIELD_NAMES'};
if ( exists $ref->{'TIED_HASH'}->{$key} ) {
# hash slice. Use -1 on split so not to strip nul fields.
@{$ref}{ @$fields_ref } =
split(/\t/,$ref->{'TIED_HASH'}->{$key},-1);
return $key;
} else {
return 0;
}
}
# And, of course, building a bit of testing code
# doesn't help. This doesn't cause an error.
# but I'm not using the real load_DBM_record().
#! /usr/local/bin/perl5 -w
use strict;
my %hash = (
'TIED_HASH' => {
1 => 'a',
2 => 'b',
3 => 'c',
},
);
my $Location_Rec = \%hash;
&build_locations_labels;
print "@{$Location_Rec->{-LABELS}}\n";
print "@{$Location_Rec->{-VALUES}}\n";
sub load_DBM_record {
my ($rec, $key ) = @_;
$rec->{'name'} = $hash{'TIED_HASH'}{$key};
return 1;
}
--
Bill Moseley mailto:moseley@best.com
------------------------------
Date: Wed, 3 Feb 1999 05:33:06 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Checking links
Message-Id: <ebohlmanF6KCr6.8tu@netcom.com>
Gala Grant <gala@sonic.net> wrote:
: I am trying to figure out how to use Perl to check links over the internet
: without actually going to the site. Can anyone help me out with any clues
: as to how to do this?
If "without actually going to the site" means "without a human having to
point a browser at the site," then use LWP to do a HEAD request on each
URL; if that fails, try a GET request and see if it works (some servers
will refuse HEAD requests). If it means "without the checking process
having to connect to the site whose link is being checked, use one of the
Clairvoyance::* modules from CPAN.
------------------------------
Date: Wed, 3 Feb 1999 01:04:07 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Filtering...
Message-Id: <1dmmj5o.1n724oge0n51aN@bay1-89.quincy.ziplink.net>
Larry Rosler <lr@hpl.hp.com> wrote:
[...discussion of filtering out strings beginning with periods...]
> Several others have posted regex-based solutions. Someone should also
> post a substr-based solution, which is significantly faster...
Based on my Benchmarks, there is no significant difference in speed when
the string begins with a period. When the string does not begin with a
period, the regex solution is slightly faster.
I also tried an index solution, which seems to be slightly faster than
substr in both cases.
use Benchmark;
$y = '.yes';
$n = 'no.';
timethese (1000000, {
regex__y => sub { $y =~ /^\./ },
regex__n => sub { $n =~ /^\./ },
substr_y => sub { substr($y, 0, 1) eq '.' },
substr_n => sub { substr($n, 0, 1) eq '.' },
index__y => sub { ! index($y, '.') },
index__n => sub { ! index($n, '.') },
});
Benchmark: timing 1000000 iterations of index__n, index__y, regex__n,
regex__y, substr_n, substr_y...
index__n: 6 secs ( 5.93 usr 0.00 sys = 5.93 cpu)
index__y: 5 secs ( 5.23 usr 0.00 sys = 5.23 cpu)
regex__n: 4 secs ( 4.88 usr 0.00 sys = 4.88 cpu)
regex__y: 6 secs ( 6.35 usr 0.00 sys = 6.35 cpu)
substr_n: 6 secs ( 6.50 usr 0.00 sys = 6.50 cpu)
substr_y: 6 secs ( 6.35 usr 0.00 sys = 6.35 cpu)
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Tue, 02 Feb 1999 23:56:17 -0500
From: Eugene Sotirescu <eugene@snailgem.org>
Subject: Re: flock not working
Message-Id: <36B7D6F1.1143926E@snailgem.org>
Debbie Whitten wrote:
>
> I've read the book, and I am trying to implement flock. Why can't I
> understand this? Am I missing something? Here is the script I wrote to
> test flock'ing. I am trying to get an exclusive lock on a file. I run
> the script and the file is supposed to stay locked until I type a u.
>
> While the file is locked, I run the script a 2nd time. I expect the 2nd
> script to wait - the file should be locked. But it does not wait - it
> goes ahead and 'locks' the file in exclusive mode. Shouldn't this be
> impossible?
>
> #!/usr/local/bin/perl -w
> use FileHandle;
> $| = 1;
> $LOCK_SH = 1;
> $LOCK_EX = 2;
> $LOCK_NB = 3;
> $LOCK_UN = 4;
> open FH, ">> test.txt";
> FH->autoflush(1);
> print "Locking file.";
> while (($x = flock ("test.txt", $LOCK_EX))) { # supposedly wait
> print "flock returned $x, $!\n"; # if the file is
> locked.
> flock (FH, $LOCK_UN);
> print ".";
> sleep 1;
> }
> print "Flock returned $x.\n";
> print "\n";
> print "Enter u to unlock: ";
> while (<STDIN> !~ /^u/) {
> print "$$ writing to file.";
> print FH "$$\n";
> print "Enter u to unlock: ";
> }
> flock (FH, $LOCK_UN);
> close FH;
1.Your first unlock doesn't work, since LOCK_UN is 8 not 4.
2.while (($x = flock ("test.txt", $LOCK_EX)))
should be
while (($x = flock (FH, $LOCK_EX)))
--
Eugene
"Light is the all-exacting good,
That dry, forever virile stream
That wipes each thing to what it is,
The whole, collage and stone, cleansed
To its proper pastoral."
Alvin Feinman
------------------------------
Date: Wed, 03 Feb 1999 04:53:03 GMT
From: jimbob4334@my-dejanews.com
Subject: Re: grep and a variable
Message-Id: <798knb$iq2$1@nnrp1.dejanews.com>
In article <aga897.787.ln@magna.metronet.com>,
tadmc@metronet.com (Tad McClellan) wrote:
> jimbob4334@my-dejanews.com wrote:
> : Can someone tell me how to use
> : grep on the following?
> : @date - is an array with many dates including 1-12-98
>
> In Perl we say that like this:
>
> @date = qw(1-10-98 1-11-98 1-12-98 1-13-98);
>
> Not too much trouble to type, and much more likely to
> contribute to your chances of getting help that you can use.
>
> : $var="1-12-98";
>
> You should not ask for interpolation if you don't need interpolation.
>
> $var = '1-12-98';
Thanks - I will read up on that.
>
> : @match = grep(/\Q$var\E/, @date);
>
> There are no regex metacharacters in your $var,
> so you don't need \Q
I put in ( in one version - so I might need it then.
>
> But it should be matching fine anyway.
>
> : $no_of_mathces = $#match;
>
> That does _not_ give the number of matches.
>
> It gives one less than the number of matches...
>
> : I get $no_of_matches = -1
>
> ... so it looks like you got zero matches.
>
thanks, that was part of the problem.
> $no_of_mathces = @match; # this really does give the # of matches
>
> There is something that you are not telling us.
>
> Show us code. Small. Complete. Shows the behavior you
> need help with.
>
> --
> Tad McClellan SGML Consulting
> tadmc@metronet.com Perl programming
> Fort Worth, Texas
>
Check out http://www.imaxx.net/~djferree
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 3 Feb 1999 05:44:11 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Help me with this small script
Message-Id: <ebohlmanF6KD9n.997@netcom.com>
LukeV <vanm01@netrevolution.com> wrote:
: @pages contains two occurences (as an example): cies_an&1 and cies_fr&1
For debugging purposes, put in:
print join ':',@pages;
and see what you get. I've got a hunch that at least one of the elements
already contains a trailing newline.
: I read them, increment their value (at the right of the &) and after that, I
: wanna write them to a file like this:
: cies_an&1 [line break]
: cies_fr&1 [line break]
: when i have only one, it's fine, it increments ok. Then, if i add another
: one, it's still ok but as soon as i wanna increment the 2nd one, the file
: looks like this:
: cies_an&1 [line break]
: [line break]
: cies_fr&1 [line break]
: here's the script:
: open(INF, ">$logfile");
Always check whether or not an open succeeded.
: foreach $i (@pages) {
: print INF "$i\n";
: }
: close(INF);
------------------------------
Date: 03 Feb 1999 06:56:38 +0100
From: Jonathan Feinberg <jdf@pobox.com>
To: pault2000@my-dejanews.com
Subject: Re: help with last modified
Message-Id: <m3u2x4xc6h.fsf@joshua.panix.com>
pault2000@my-dejanews.com writes:
> next if -M $file > 1; # skip files modified before today
The files are in /some/other/directory. The current working directory
is not. You follow?
perldoc -f readdir
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Tue, 02 Feb 1999 23:26:34 -0500
From: Eugene Sotirescu <eugene@snailgem.org>
To: kiml@worldnetla.net
Subject: Re: locking/linking files - HELP
Message-Id: <36B7CFFA.5A0FB4C1@snailgem.org>
Kim Long wrote:
>
> I have a book with this snippet of code for locking a file before
> manipulation. However there are a few things I don't understand. Here
> goes:
>
> $PtmpTmp = "ptmp$$";
> open(PTMPTMP,">$PtmpTmp") || die "Can't create temporary passwd file, $!\n";
> close(PTMPTMP);
> for ($i=1;$i<=60;$i++) {
> $GotPtmp = link($PtmpTmp,"ptmp");
> if ($GotPtmp) {
> unlink $PtmpTmp;
> ($i == 1) || print "\n"; # If no dots, no newline
> last;
> }
> ($i == 1) && print "Waiting for lock on /etc/passwd\n";
> print ".";
> sleep 1;
> }
> $GotPtmp || &ABORT("\nCan't get lock on /etc/passwd");
>
> The text description says "The passwd file needs to be locked to prevent
> multiple processes.... Create a file called /etc/ptmp. The open system
> call is not guaranteed to be atomic....link call will be atomic. Create a
> file that can be linked to ptmp. Then loop up to 60 times trying to get the
> lock. Remove temp file linked to ptmp. (give feedback to user in the form
> of dots while looping through trying to get lock - waiting 1 sec between
> loops) If lock couldn't be aquired, call ABORT ..."
>
> Later:
> open(PASSWD,"passwd") || &ABORT("Can't open /etc/passwd, $!");
> open(PTMP,">ptmp") || &ABORT("Can't open /etc/ptmp, $!");
> .
> .
> while (<PASSWD>) {
> print PTMP;
>
> Here's my question/s: (And I have tried RTM)....
> 1) I understand creating the file, but what is "$$" in $PtmpTmp = "ptmp$$"
> ?
Really tried the docs?
>From perlvar:
$$ The process number of the Perl running this
script.
> 2) My understanding is we need to link to the file in order to prevent it
> from being changed, but I don't see a
> link to the passwd file itself, only this temp file.
> 3) If we're linking to the temp of the temp to lock it, then why do we
> unlink before anything is written to it?
>
> I'm sure I'm simply missing a concept; I'm still new to Perl. I'm running
> out of time to finish a project and I want to use this concept to lock my
> file. - unless there's a easier/better way.
open (FH, ">$file") or die "Can't open $file: $!;
flock (FH, 2); #use exclusive lock on file
#do stuff to file
close FH;
Note tho that for the lock to work, other programs accessing the file
also have to honor flock.
--
Eugene
"Light is the all-exacting good,
That dry, forever virile stream
That wipes each thing to what it is,
The whole, collage and stone, cleansed
To its proper pastoral."
Alvin Feinman
------------------------------
Date: Tue, 2 Feb 1999 18:08:17 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
To: Gavin Ian Andrew Kenny <eem3gk@ee.surrey.ac.uk>
Subject: Re: newbie having trouble with concatination
Message-Id: <x3y7lu0mmjj.fsf@tigre.matrox.com>
Gavin Ian Andrew Kenny <eem3gk@ee.surrey.ac.uk> writes:
> I'm writing a script that reads a VHDL text file
> and pulls out data from it.
>
> Part of the problem is that lines are longer than
> a single line. Also the text is pretty haphazardly formatted.
In general, VHDL code ends with a semicolon .. so maybe you can play
around with the $/ special variable. Read about it in perlvar for more
info. It might help you a lot.
> So I wrote the following code to go through the file line by line
> and put all the lines I'm interested in, into a single string so I could
> then split it up
> and count things.
>
> $line =~ /\s*(\S+.*)$/; # this gets rid of tab at the start and \n
> at # the end
> $clean_line = $1;
well, you can do both of the above steps in one:
($clean_line = $line) =~ s/^\s*|\s$//g;
or if you don't want to use two variables:
$line =~ s/^\s*|\s*$//g;
> $port = join ' ',$port,$clean_line; # $port is an earlier line "cleaned"
> # in exaclty the same way.
I wouldn't use join() here. A simple concatenation using the
'.' (single dot) operator is sufficient. But .. join() should also
work.
$port .= $clean_line;
or maybe
$port .= " $clean_line";
> ...
>
> The trouble is, instead of the new $port being a concatenation of the
> two strings, it just overlays them one on top of the other and makes
> a right mess.
Are you sure? what do you mean it overlays them one of top of the
other? it works as expected for me .. witness:
% perl -w
$a = "hello";
$b = "world";
$a = join ' ', $a, $b;
print "$a.\n";
__END__
hello world.
> can anyone point out where I'm going wrong
Maybe your $port or $clean_line variables are screwed up. Did you
check their contents before the join?
> ta
>
> Gavin
HTH,
Ala
------------------------------
Date: Wed, 3 Feb 1999 01:04:08 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Perl bug on search patterns?
Message-Id: <1dmmk8r.14nk9n315d04ubN@bay1-89.quincy.ziplink.net>
Aaron Tavistock <aarontav@cs.berkeley.edu> wrote:
> I'm not entirely sure on the internals of perl that make this not work,
> but I do know that you can't just shove a standard string into a regex
> and expect it to evaluate properly. I'm guessing that its related to
> there not being an explicit 'e' modifier to m//
Actually, you *can* just shove a standard string into a regex and expect
it to evaluate properly. The trick is to make sure the string is what
you think it is.
$re = "(\w+)"; # $re is now '(w+)'
$re = '(\w+)'; # $re is now '(\w+)'
By the way, /e is not even a legal modifier for m//. It's only allowed
on s///, where it applies to the replacement expression.
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 03 Feb 1999 01:10:19 -0500
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: Perl bug on search patterns?
Message-Id: <x73e4oow50.fsf@home.sysarch.com>
>>>>> "AT" == Aaron Tavistock <aarontav@cs.berkeley.edu> writes:
AT> Patrice Chalin (EX:MTL:6V41) wrote:
>>
>> | my $pattern = "^\s*class";
AT> I'm not entirely sure on the internals of perl that make this not work,
AT> but I do know that you can't just shove a standard string into a regex
AT> and expect it to evaluate properly. I'm guessing that its related to
yes you can. she just didn't quote it correctly. either sha has to
backwhack the backwhack or single quote the string. the naked \ is lost
in "" and the \s becomes a plain s which creates a different regex.
very simple.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---------------------- Perl, Internet, UNIX Consulting
uri@sysarch.com ------------------------------------ http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Wed, 03 Feb 1999 05:32:09 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: perlscript with ASP
Message-Id: <tbRt2.157$9v3.9329@nsw.nnrp.telstra.net>
In article <79a1mf$auj3@indo-news>,
"news.dnet.net.id" <usagi@indo-mail.com> writes:
> Does anyone know how to read
Yes.
> and write
Yes.
> using ASP in perlscript language..?
read what? write what? books? memos? notes? words? files? What does
the perlscript documentation or the ASP documentation have to say
about that?
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | What's another word for Thesaurus?
NSW, Australia |
------------------------------
Date: Tue, 02 Feb 1999 23:39:27 -0500
From: Eugene Sotirescu <eugene@snailgem.org>
To: Guillaume Buat-Menard <guillaume@nospam.com>
Subject: Re: read an html from a url
Message-Id: <36B7D2FF.8BAE8FFC@snailgem.org>
Guillaume Buat-Menard wrote:
>
> Hi All,
>
> I know there are some packages dedicated to the internet etc...
> The problem is that I don't want to download or install any package because
> I'm not gonna run the script on my test server but on another server that I
> don't know yet.
>
> I just need to find a routine or a compact package that will allow me to
> read an HTML (or text) page from a designated URL
> (http://theserver.com/myfile.html). I would like to run this package or
> routine on NT and UNIX with perl 5.
Not sure what you mean by 'compact package'.
I use LWP for this kind of thing, but if you insist there's an antique
called wwwgrab.pl that might do what you want:
http://zima.cae.wisc.edu/~ballard/projects/wwwgrab
In the long run, you shoot yourself in the foot by using it tho: you'll
have to hack it to do anything interesting (we still have stuff like
wwwgrab_with_post.pl and a wwwgrab_with_cookies.pl lying around on the
server where I work). Learn/use LWP.
--
Eugene
"Light is the all-exacting good,
That dry, forever virile stream
That wipes each thing to what it is,
The whole, collage and stone, cleansed
To its proper pastoral."
Alvin Feinman
------------------------------
Date: Wed, 3 Feb 1999 01:04:09 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Statistics for comp.lang.perl.misc
Message-Id: <1dmmkvj.157w8c6hayyosN@bay1-89.quincy.ziplink.net>
Bill Moseley <moseley@best.com> wrote:
> What a nice service this summary is.
>
> > - Original Content Rating (OCR) is the ratio of the original content
> > volume to the total body volume.
>
> Is a high ratio good or bad???
In theory, a high ratio is good. High ratio == more original context.
Low ratio == more quoted text.
In practice, if you feel your post needs a big chunk of quoted text to
put it in context, go for it. Don't worry about OCR.
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Tue, 2 Feb 1999 22:32:28 -0800
From: moseley@best.com (Bill Moseley)
Subject: Re: Statistics for comp.lang.perl.misc
Message-Id: <MPG.11218d53886948f998969d@nntp1.ba.best.com>
In article <1dmmkvj.157w8c6hayyosN@bay1-89.quincy.ziplink.net>,
rjk@linguist.dartmouth.edu says...
> Bill Moseley <moseley@best.com> wrote:
>
> > What a nice service this summary is.
> >
> > > - Original Content Rating (OCR) is the ratio of the original content
> > > volume to the total body volume.
> >
> > Is a high ratio good or bad???
>
> In theory, a high ratio is good. High ratio == more original context.
> Low ratio == more quoted text.
That seems to devalue those nice one or two lines of perl that so
beautifully answer some long question!
And with CPAN's help, it's often recommended to have a low OCR in my
programming....
--
Bill Moseley mailto:moseley@best.com
------------------------------
Date: Tue, 2 Feb 1999 23:03:52 -0500
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: Stopping a foreach loop
Message-Id: <1dmenks.1cykeqq1ied7yoN@slip166-72-108-31.ny.us.ibm.net>
James Ludlow <ludlow@us.ibm.com> wrote:
> > > Is there anyway to break (stop) a foreach loop?
> >
> > perldoc -f last
> > perldoc -f return
> > perldoc -f exit
> > perldoc -f die
> > perldoc -f exec
> >
> > even (ugh!)
> >
> > perldoc -f goto
> >
> > That's off the top of my head. Did I miss any?
>
> system("/sbin/shutdown -r now");
perl -e 'for (;;) {$x = [$x, (1..10000)];}'
Out of memory!
--
@s=(0)x79;@c=split//,q< !_@,#.$%^&*()-+={[}]|\:;"'<>?/>;for(;;){for($d=1;$d<$#s
;$d++){$s[$d]+=((($s[$d-1]+$s[$d]+$s[$d+1])/3)-$s[$d])*.1+((rand)-.5)}print+map
($c[$_%(scalar@c)],@s),"\n"}
------------------------------
Date: Wed, 3 Feb 1999 01:04:10 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: tie, hash problem
Message-Id: <1dmml8u.oor18e14gqnd9N@bay1-89.quincy.ziplink.net>
Andrew Fry <andrewf@beausys.demon.co.uk> wrote:
> tie(%DBHASH,$i,$dbname,$flags,0666)
> where $i = SDBM_Type or DB_Type or NDBM_Type
Shouldn't that be SDBM_File or DB_File or NDBM_File?
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 03 Feb 1999 07:12:51 +0100
From: Jonathan Feinberg <jdf@pobox.com>
To: Andrew Fry <andrewf@beausys.demon.co.uk>, Andrew Fry <andrewf@beausys.demon.co.uk>
Subject: Re: tie, hash problem
Message-Id: <m3pv7sxbfg.fsf@joshua.panix.com>
Andrew Fry <andrewf@beausys.demon.co.uk> writes:
> tie(%DBHASH,$i,$dbname,$flags,0666)
> where $i = SDBM_Type or DB_Type or NDBM_Type
> "Cant locate object method "TIEHASH" via package (xxx)"
There's no such thing as SDBM_Type or DB_Type or NDBM_Type. Unless
you've written them yourself...
perldoc AnyDBM_File
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Wed, 03 Feb 1999 06:59:37 +0100
From: martin@RADIOGAGA.HARZ.DE (Martin Vorlaender)
Subject: Re: web load testing code
Message-Id: <36b7e5c9.524144494f47414741@radiogaga.harz.de>
Tom Bates (ctbates@tva.gov) wrote:
: Is anyone aware of any published perl code or modules out there for load
: testing a web server?
Not Perl, but anyway: for Win32, there's a tool called Socrates.
Can't remember where I got it, though.
cu,
Martin
--
| Martin Vorlaender | VMS & WNT programmer
VMS is today what | work: mv@pdv-systeme.de
Microsoft wants | http://www.pdv-systeme.de/users/martinv/
Windows NT 8.0 to be! | home: martin@radiogaga.harz.de
------------------------------
Date: 12 Dec 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 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 4812
**************************************