[13632] in Perl-Users-Digest
Perl-Users Digest, Issue: 1042 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 11 17:05:41 1999
Date: Mon, 11 Oct 1999 14:05:16 -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: <939675915-v9-i1042@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 11 Oct 1999 Volume: 9 Number: 1042
Today's topics:
-w, do and "name used only once" adrianonr@my-deja.com
Advanced text substitution in FILEHANDLES <pb@decoteka.com>
Re: Advanced text substitution in FILEHANDLES <rasmusr@online.no>
Re: Advanced text substitution in FILEHANDLES (Larry Rosler)
Re: Advanced text substitution in FILEHANDLES (Kragen Sitaker)
Re: Case Question. (Larry Rosler)
Re: Case Question. (Larry Rosler)
Re: Case Question. (Craig Berry)
Re: CGI.pm: Setting `Type' for stylesheets - How? <dove@synopsys.com>
DBI and Taint mode question <tyr@tiamat.lethean.net>
Debugging 'segmentation fault' errors jboes@my-deja.com
Re: Dedicated Server <cumhur.ozkan@janset.com>
die <frankhale@trespass.net>
Re: die <dove@synopsys.com>
Re: downloading and comparing all bookmarks out of a bo <dtbaker_@busprod.com>
hidden field displays old value <nospam_antoine@nospam_natuur.org>
Re: I need some Perl help (Alan Curry)
Re: I need some Perl help (Abigail)
Re: Modifying subroutine arguments (Larry Rosler)
Re: newbie question about quotes in code <jeff@vpservices.com>
Re: Opening files on Windows NT <lee@insync.net>
Re: parenthesizing arguments to grep - BLOCK form jrw32982@my-deja.com
Re: parenthesizing arguments to grep - BLOCK form jrw32982@my-deja.com
Perl Interview Question: <samay1NOsaSPAM@hotmail.com.invalid>
Re: Perl lite <makkulka@cisco.com>
Re: Perl lite (Abigail)
Re: Perl lite (ItsMe9905)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 11 Oct 1999 19:50:47 GMT
From: adrianonr@my-deja.com
Subject: -w, do and "name used only once"
Message-Id: <7ttf2h$c0g$1@nnrp1.deja.com>
Hi,
I'm parsing a simple configuration file (it only has variable
assignments, is written in Perl and has its own packge Conf)
with "do" from several scripts.
I would like to get rid of the "used only once" warnings generated by
-w. I can't "use vars" because the vars in question are in another name
space. Besides, if I make a typo there'll be a "use of uninitialized
value" message to warn me.
Is there a way out without explicitly referencing all the used only
once variables again? What's the right thing to do here?
Thanks,
--
Adriano
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 11 Oct 1999 12:02:26 -0700
From: "PB" <pb@decoteka.com>
Subject: Advanced text substitution in FILEHANDLES
Message-Id: <7ttcb1$8t4$1@birch.prod.itd.earthlink.net>
I'm new to Perl and have read "Learning Perl" and am half way through
"Programming Perl". However, I have not found a way to do the following:
Taking the following txt file as input to a FILEHANDLE (in this case
sample.txt) and print output (after cleaning with s///) to FILEHANDLE2
--------- start sample.txt ----------------
john
doe
blow
mike
Above name is not in group
susan
peter
gerry
Above name is not in group
james
----------- end sample.txt -------------
I'm trying to get rid of lines that read:
"Above name is not in group"
and the name on the line just above that.
In this case, I would like to get rid of:
mike
Above name is not in group
gerry
Above name is not in group
and print the remaining of the file to FILEHANDLE2.
Does anyone know how to do this?
Cheers,
pb
------------------------------
Date: Mon, 11 Oct 1999 21:46:51 +0100
From: "Rasmus Rimestad" <rasmusr@online.no>
Subject: Re: Advanced text substitution in FILEHANDLES
Message-Id: <r8rM3.3901$nU4.20023@news1.online.no>
You know, that's a really hard way of doing it. Much harder than necessary.
Why don't you put the line above the name instead? That'd make it a great
deal easier, but I've come up with a solution which follows here:
open(FILEHANDLE,"sample.txt");
@before = <FILEHANDLE>;
close(FILEHANDLE);
foreach $line (@before) {
if($line ne "Above name is not in group\n") {
@after[$i] = $oldName;
$i++;
$oldName = $line;
} else {
$oldName = "";
}
}
if($line ne "Above name is not in group\n") {
@after[$i] = $oldName;
$i++;
$oldName = $line;
}
open(FILEHANDLE,">sample.txt");
print FILEHANDLE (@after);
close(FILEHANDLE);
This is a bad way of doing it, so if someone else offers you a better
solution, use it instead of mine (quite logical. You'd do that anyway I
guess :o)
Yours sincerely
Rasmus Rimestad, first follower of the blue hen
rasmusr@online.no
http://dikt.cjb.net
http://bullshitprod.virtualave.net
------------------------------
Date: Mon, 11 Oct 1999 12:51:51 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Advanced text substitution in FILEHANDLES
Message-Id: <MPG.126bdfb17d25252798a075@nntp.hpl.hp.com>
In article <7ttcb1$8t4$1@birch.prod.itd.earthlink.net> on Mon, 11 Oct
1999 12:02:26 -0700, PB <pb@decoteka.com> says...
...
<SNIP> of data reproduced below
> I'm trying to get rid of lines that read:
> "Above name is not in group"
> and the name on the line just above that.
>
> In this case, I would like to get rid of:
> mike
> Above name is not in group
> gerry
> Above name is not in group
>
> and print the remaining of the file to FILEHANDLE2.
This can be done simply by buffering a line before printing it,
depending on the contents of the next line. I think the way shown below
is nicer (i.e., more Perlish).
Omitting the details of opening the input and output files:
#!/usr/local/bin/perl -w
use strict;
{
local $/ = "\nAbove name is not in group\n";
while (<DATA>) {
chomp and s/[^\n]+$//;
print;
}
}
__END__
john
doe
blow
mike
Above name is not in group
susan
peter
gerry
Above name is not in group
james
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 11 Oct 1999 20:11:11 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Advanced text substitution in FILEHANDLES
Message-Id: <zvrM3.6633$UG5.436115@typ11.nn.bcandid.com>
In article <r8rM3.3901$nU4.20023@news1.online.no>,
Rasmus Rimestad <rasmusr@online.no> wrote:
>You know, that's a really hard way of doing it. Much harder than necessary.
>Why don't you put the line above the name instead?
The world would be a much simpler place if we could always determine
the format of our input data. Indeed, all our programs would be
'cat'. :)
> That'd make it a great
>deal easier, but I've come up with a solution which follows here:
>
>
>open(FILEHANDLE,"sample.txt");
or die! I mean, what happens if FILEHANDLE doesn't open?
>@before = <FILEHANDLE>;
>close(FILEHANDLE);
>foreach $line (@before) {
> if($line ne "Above name is not in group\n") {
> @after[$i] = $oldName;
> $i++;
> $oldName = $line;
> } else {
> $oldName = "";
> }
>}
>
>if($line ne "Above name is not in group\n") {
> @after[$i] = $oldName;
> $i++;
> $oldName = $line;
>}
>
>open(FILEHANDLE,">sample.txt");
>print FILEHANDLE (@after);
>close(FILEHANDLE);
>
>This is a bad way of doing it, so if someone else offers you a better
>solution, use it instead of mine (quite logical. You'd do that anyway I
>guess :o)
Here's an example. You might look at the 'context grep' contest of a
week or two ago for further inspiration, too.
#!/usr/bin/perl -w
use strict;
my $lastline = '';
while (<DATA>) {
if ($_ eq "Above name is not in group\n") {
$lastline = '';
} else {
print $lastline;
$lastline = $_;
}
}
print $lastline;
__DATA__
asdf
bwojig
Above name is not in group
owgijweoi
wrojihjwo
giwejogjiewi
Above name is not in group
Above name is not in group
jgoweij
iowjgo
Above name is not in group
This gives as output:
asdf
owgijweoi
wrojihjwo
jgoweij
This is correct.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
Mon Oct 11 1999
29 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Mon, 11 Oct 1999 12:03:52 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Case Question.
Message-Id: <MPG.126bd475c42ceec098a072@nntp.hpl.hp.com>
In article <3802153A.B42F440@papillonres.com> on Mon, 11 Oct 1999
12:50:02 -0400, Kevin McCluskey <kevinm@papillonres.com> says...
> I am trying to check a variable against an array of keywords and cannot
> get it to ignore the case.
> This is what I have:
>
> $kw_len = @keywords;
>
> sub keytest {
> for($i=0;$i<$kw_len;$i++)
> {
> if ($word eq $keywords[$i]){
> return 1;}
> }
> }
sub keytest {
my $lc_word = lc $word;
$lc_word eq lc and return 1 for @keywords;
}
You might better pass the variable to the subroutine as an argument
instead of as a global variable:
my $lc_word = lc shift;
It would be more efficient to one-case @keywords once before using it,
then replace 'lc' by '$_' in the subroutine.
$_ = lc for @keywords;
> If I do: $word eq /$keywords[$i]/i
> I don't get a compare.
>
> Any ideas ? is it that the "eq" operator does not work right with /i ?
The 'eq' operator does not work right with any regex! It compares two
strings.
To get the truth value of a regex match, use the '=~' (bind) operator.
But that gets you into problems with inner matches (anchor with '^' and
'$') and with metacharacters (surround with '\Q' and '\E'). The direct
comparison shown above is much cleaner and faster.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 11 Oct 1999 12:18:13 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Case Question.
Message-Id: <MPG.126bd7d05cfff6b798a073@nntp.hpl.hp.com>
In article <s04calhch1s56@corp.supernews.com> on Mon, 11 Oct 1999
18:49:57 GMT, Craig Berry <cberry@cinenet.net> says...
...
> ... Note also that I've set it up to receive the search target and
> the list to search as arguments, which is generally prefered to using
> globals. ...
It would be more efficient to pass the comparison array by reference
rather than by value. If there is never more than one such array, I see
nothing wrong with a global variable, though I might make it private to
the subroutine:
{ my @keywords = qw(blah bleah foo quux boo nah);
sub keytest {
...
} }
> sub keytest {
> my ($word, @keywords) = @_;
> $word = lc $word; # Normalize $word for comparisons
> return scalar grep { $word eq lc } @keywords;
> }
I don't think one should overlook what perlfaq4: "How can I tell whether
a list or array contains a certain element?" has to say about this code:
<QUOTE>
Please do not use
$is_there = grep $_ eq $whatever, @array;
... slow (checks every element even if the first matches), inefficient
(same reason), ...
</QUOTE>
The poster's early-exit code was better than this 'grep' in scalar
context.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 11 Oct 1999 20:30:15 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Case Question.
Message-Id: <s04i6nrjh1s76@corp.supernews.com>
Larry Rosler (lr@hpl.hp.com) wrote:
: sub keytest {
: my $lc_word = lc $word;
: $lc_word eq lc and return 1 for @keywords;
: }
I like Larry's for-based solution better than my grep; his exits early
once any match is found, while mine always checks the entire list of
keywords.
: It would be more efficient to one-case @keywords once before using it,
: then replace 'lc' by '$_' in the subroutine.
:
: $_ = lc for @keywords;
Would that be more efficient? Pre-lc'ing requires that all keys be
lowercased; the early-exit loop requires on average half of them.
This argument goes away if you lc @keywords once outside the subroutine
(and the keyword list is fixed), of course.
--
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| "There it is; take it." - William Mulholland
------------------------------
Date: Mon, 11 Oct 1999 14:01:31 -0700
From: David Amann <dove@synopsys.com>
Subject: Re: CGI.pm: Setting `Type' for stylesheets - How?
Message-Id: <3802502B.37847604@synopsys.com>
Hi Jerry,
Jerry Pank wrote:
> Using CGI.pm, could someone kindly modify my example below, to output:
>
> <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
> <HTML><HEAD><TITLE>Stylish Docs</TITLE>
> <STYLE TYPE="text/css"><!--
> a:{color:{#000000}....
>
> #!/bin/perl5 -w
> use CGI qw(:all);
> print header,
> start_html(-TITLE => 'Stylish Docs',
> -STYLE => "<!--\na:{color:{#000000}
> a:vlink{color:#2222FF}
> a:hover{color:#FF0000}-->\n"),
> h1("It's the way you wear it...\n"),
> a({-HREF => 'Foo.htm'}, 'Only Me!'),".\n",
> end_html;
Implement your -style tag as follows:
print start_html("-style" => {"-type" => "text/css",
"-code" =>
$your_style_sheet_code
});
You'll need to make sure your using version 2.38 of CGI.pm or later. In
version 2.38 or later you really won't need the '-type' flag. It should
default to "text/css" (at least it does for me).
Hope this helps,
-=dav
------------------------------
Date: Mon, 11 Oct 1999 20:00:54 GMT
From: Bolt Thrower <tyr@tiamat.lethean.net>
Subject: DBI and Taint mode question
Message-Id: <WlrM3.85$F3.175913984@news.frii.net>
Hello,
I could not find an answer to my question in the DBI man pages, the
Mysql documentation nor the perlsec page. So, hopefully someone here
can either answer this directly or point me to where I need to or have
forgotten to read.
According to perlsec's discussion of taint mode,
You may not use data derived from outside your program to affect
something else outside your program--at least, not by accident.
So, I was wondering why perl doesn't complain when I run a query
wherein I use data from the outside, namely an environment variable:
(I've tested the following with an UPDATE query as well, both execute()
fine and return expected results.)
---[start]-----
#!/usr/bin/perl -Tw
use strict;
use DBI;
my $dbh = DBI->connect("DBI:mysql:mydb:host", "dbuser", "password") ||
print "Can't connect : $Mysql::db_errstr \n";
my $auth_user = $ENV{'REMOTE_USER'}; # $auth_user now tainted...
my $sth = $dbh->prepare("
SELECT *
FROM login_info
WHERE user_name = ?") || die "prepare failed";
# calling execute() with tainted data
$sth->execute($auth_user) || die "execute failed";
while(my @arr = $sth->fetchrow()) {
print "@arr\n";
}
$sth->finish;
$dbh->disconnect();
---[end]-----
Specifically, it seems to me that since the DBI module is affecting
something outside my program, namely the database, perl should complain
about my use of an environment variable.
Is it because
a) I've done somthing wrong or stupid,
b) DBI doesn't do anything that's considered affecting anything
outside my program,
c) ????
Specifics:
5.005_02 built for sun4-solaris
Sparc Solaris 2.5.1
$DBI::VERSION = '1.06';
Thanks for any and all suggestions!
--
Steve <tyr@lethean.net>
------------------------------
Date: Mon, 11 Oct 1999 20:43:00 GMT
From: jboes@my-deja.com
Subject: Debugging 'segmentation fault' errors
Message-Id: <7tti4g$ebm$1@nnrp1.deja.com>
How does one go about trying to figure out 'segmentation fault' errors
from a Perl script? The script isn't doing anything in particular; at
the point of the error it appears to be executing
return 0;
from a subroutine in a package back to my main program.
--
Jeff Boes jboes@qtm.net
http://www.qtm.net/~jboes/
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 11 Oct 1999 23:38:00 +0200
From: "Cumhur Ozkan" <cumhur.ozkan@janset.com>
Subject: Re: Dedicated Server
Message-Id: <7ttib2$i3b$1@defne.istanbul.edu.tr>
if it really a dedicated linux server that DN offers i would like to learn
their web address to check what the offerring includes.
Because all the relaible dedicated servers that i looked for are about 1000
$s per month and i did not even heard a low price like 300 $ s.
Regards
Cumhur
John wrote in message <7tsfo8$nkm$1@wanadoo.fr>...
>Hi,
>
>I know this is not a Perl/CGI question, but I thought
>some of you could helpt it. Please accept
>my appologizes If I am bothering.
>
>Does anybody know a good company that offers
>reliable Linux dedicated servers ? DN offers this
>at 300 dollars a month, which I think is a little
>bit expensive. Any Help would be highly appreciated.
>Thank you,
>
>John
>
>
>
------------------------------
Date: Mon, 11 Oct 1999 16:19:45 -0500
From: Frank Hale <frankhale@trespass.net>
Subject: die
Message-Id: <38025471.D7BA0F9@trespass.net>
Howcome the die command doesn't work in a browser when you execute a
cgi? How would I implement the same thing for a cgi?
print "Content-Type: text/html\n\n";
$USERS{"frank"}="111";
foreach $user (keys %USERS)
{
#print $user, ' has the password ', $USERS{$user};
#print "\n";
$name = "frank";
$pw = "aaa";
die ("User does not exist\n") unless (defined $USERS{$name});
die ("go away script kiddy") unless ($USERS{$name} eq $pw);
}
print "cool your a user!\n";
All I get is "Document contains no data" errors when infact it should
execute the die command and print a message.
What am I doing wrong?
--
From: Frank Hale
Email: frankhale@yahoo.com
ICQ: 7205161
------------------------------
Date: Mon, 11 Oct 1999 13:34:38 -0700
From: David Amann <dove@synopsys.com>
Subject: Re: die
Message-Id: <380249DE.638CAC88@synopsys.com>
Hi Frank,
Frank Hale wrote:
> Howcome the die command doesn't work in a browser when you execute a
> cgi? How would I implement the same thing for a cgi?
Since die gets redirected to STDERR and not STDOUT, the web server won't
pass it on. Try using the CGI::Carp module as follows:
use CGI::Carp qw/fatalsToBrowser/;
This should redirect your die commands to the browser.
Hope this helps,
-=dav
------------------------------
Date: Mon, 11 Oct 1999 15:49:01 -0500
From: Dan Baker <dtbaker_@busprod.com>
Subject: Re: downloading and comparing all bookmarks out of a bookmark file
Message-Id: <38024D3D.79F2CA29@busprod.com>
Abigail wrote:
>
> Stefan Goerres (stefan.goerres@xsc.net) wrote on MMCCXXXII September
> MCMXCIII in <URL:news:7tsk0e$amv$1@fu-berlin.de>:
> $$ Well ... I want to write a script that is downloading all my bookmarked
> $$ pages and automatically checks if they changed. Is that possible .. ---------------------
sure its possible.
but you might want to use a free tool that does this for you already
like by signing up at http://www.netmind.com
Dan
------------------------------
Date: Mon, 11 Oct 1999 22:33:41 +0200
From: "Antoine" <nospam_antoine@nospam_natuur.org>
Subject: hidden field displays old value
Message-Id: <7tth82$k08$1@news.telekabel.nl>
I' ve written a perl cgi script to select a location on the web server to
create a new folder in. I call this scipt several times to enter deeper in
the tree structure. A hidden field contains the current dir but when i call
the script for the second time it will not refresh the value of the hidden
field. What goes wrong. Are the values in hidden fields cached? how to
resolve this?
$current_dir = "$current_dir/$selected_dir";
print "The current folder is <b>$current_dir</b>.";
print startform;
print @input;
print textfield(-name=>'new_folder', -size=>20);
print checkbox(-name=>'browsable', -value=>'no',-label=>'Disable
directory listing');
print hidden(-name=>'current_dir', -value=>$current_dir);
print submit(-name=>'action', -value=>'submit');
print endform;
$current_dir in the second line shows an other value the $current_dir in the
hidden field!
Antoine
------------------------------
Date: Mon, 11 Oct 1999 19:27:25 GMT
From: pacman@defiant.cqc.com (Alan Curry)
Subject: Re: I need some Perl help
Message-Id: <xSqM3.6508$UG5.426019@typ11.nn.bcandid.com>
In article <38022c07.251886@news.skynet.be>,
Bart Lateur <bart.lateur@skynet.be> wrote:
>Abigail wrote:
>
>>Oh gosh, don't tell me Perl is making needless copies. It shouldn't
>>do that.
>
>Shouldn't it?
I believe Abigail meant it should do copy-on-write.
--
Alan Curry |Declaration of | _../\. ./\.._ ____. ____.
pacman@cqc.com|bigotries (should| [ | | ] / _> / _>
--------------+save some time): | \__/ \__/ \___: \___:
Linux,vim,trn,GPL,zsh,qmail,^H | "Screw you guys, I'm going home" -- Cartman
------------------------------
Date: 11 Oct 1999 14:52:49 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: I need some Perl help
Message-Id: <slrn804g03.gep.abigail@alexandra.delanet.com>
Bart Lateur (bart.lateur@skynet.be) wrote on MMCCXXXII September MCMXCIII
in <URL:news:38022c07.251886@news.skynet.be>:
$$
$$ >Oh gosh, don't tell me Perl is making needless copies. It shouldn't
$$ >do that.
$$
$$ Shouldn't it?
$$
$$ $_ = "abc";
$$ $hash{$_} = 123;
$$ substr($_,1,1) = "X";
$$ print "$_:$hash{$_}:$hash{abc}\n";
$$ -->
$$ Use of uninitialized value at test.pl line 4.
$$ aXc::123
$$
$$ The "uninitalized value" is of course the hash value for the new $_.
$$ Now, I *must* have two copies of the string "abc", and only one of them
$$ ($_) is changed to "aXc". The hash key itself is not affected. Good.
Copy-on-write.
Abigail
--
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Mon, 11 Oct 1999 12:35:59 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Modifying subroutine arguments
Message-Id: <MPG.126bdbf88162f3f98a074@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <7tt8o1$6rn$1@nnrp1.deja.com> on Mon, 11 Oct 1999 18:02:50
GMT, rwentwor@advent.com <rwentwor@advent.com> says...
...
> I'm trying to pass two variables to a subroutine and modify the values.
Actually, you are trying to pass the names of two variables to a
subroutine and modify the values. You do not use the values of the
variables inside the subroutine.
So, by far the best solution to your problem is simply to pass the
returned values as the return value of the subroutine.
($Username, $Path) = GetCheckoutInfo('status.lst');
sub GetCheckoutInfo {
...
substr($Line,20,8), substr($Line, 56)
}
...
> Here's the subroutine:
>
> sub GetCheckoutInfo {
>
> my $Filename = shift;
> local *User = \$_[0];
> local *Dir = \$_[1];
Using 'local' is almost always wrong, when 'my' will work.
my $User = \$_[0];
my $Dir = \$_[1];
But why go through these contortions? See below.
...
> I prefer to keep the extra safeties turned on.
Indeed!
> I was finally able to
> get it working by deleting the two "local" lines and replacing the last
> two lines with:
>
> $_[0] = substr($Line,20,8);
> $_[1] = substr($Line, 56);
>
> I can live with this solution for this short subroutine. However, it
> still annoys me that I can't figure out how to do this in the "proper"
> fashion. I feel this will become important in a more complicated
> subroutine when using "$_[?]" would be too cryptic.
To me, this is the 'proper' fashion for modifying arguments (though I
hate to do that in any case -- return the values, as I showed above).
To document it better, you could use named constants for the indexes
(`perldoc constant`).
> Could someone please enlighten me as to the proper way to work with
> variables by reference. Thanks.
Yes. Don't. :-)
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 11 Oct 1999 19:38:39 GMT
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: newbie question about quotes in code
Message-Id: <38023C76.1FD633A7@vpservices.com>
clavikal wrote:
>
> I always get an error message (from the www) when putting quotes in HTML
> inside a perl program. Is there a way to be able to include quotes?
>
> i.e.
> print("<img src="blah/blah.gif">");
> Anything like this will give me an error.
Use the qq operator: print qq(<img src="blah/blah.gif">);
And while you're at it, don't forget the alt="description" part of the
tag!
--
Jeff
------------------------------
Date: Mon, 11 Oct 1999 15:08:35 -0500
From: "Lee Sharp" <lee@insync.net>
Subject: Re: Opening files on Windows NT
Message-Id: <7trM3.7747$Ph7.38451@insync>
jakal wrote in message ...
|I have done a little programming in Perl, mostly on my Macintosh.
|I am trying to port a script to a Windows NT machine, and am having
|trouble accessing files. my code looks like this:
| open(TEST, ">>test.txt")|| die "can't open test.txt";
|and the program dies at this point (the first time I try to access a file).
|Is this something to do with file permissions or is it a syntax problem??
Several possibilities. You can specify the full path, but that makes it
non-portable. I use this in a knows good script...
$main::Homedir = get_homedir($0);
...
open (INDEX,">$main::Indexfile.$$") || die "Cannot open $main::Indexfile
($OS_ERROR)";
This makes it still portable to Unix OS's. Also cleaner when you move
things.
Lee
--
SCSI is *NOT* magic. There are *fundamental technical reasons* why it is
necessary to sacrifice a young goat to your SCSI chain now and then. * Black
holes are where God divided by zero. - I am speaking as an individual, not
as a representative of any company, organization or other entity. I am
solely responsible for my words.
--
SCSI is *NOT* magic. There are *fundamental technical reasons* why it is
necessary to sacrifice a young goat to your SCSI chain now and then. * Black
holes are where God divided by zero. - I am speaking as an individual, not
as a representative of any company, organization or other entity. I am
solely responsible for my words.
------------------------------
Date: Mon, 11 Oct 1999 20:01:50 GMT
From: jrw32982@my-deja.com
Subject: Re: parenthesizing arguments to grep - BLOCK form
Message-Id: <7ttfn4$cf9$1@nnrp1.deja.com>
In article <X_oM3.5896$UG5.406627@typ11.nn.bcandid.com>,
pacman@defiant.cqc.com (Alan Curry) wrote:
> >BTW, what do you call those thingies and what exactly is their
> >syntactic
> >status. I haven't seen much discussion in the manual about them.
> >How
> >do you search for something like that?
>
> In the case of grep, it's an anonymous sub. The same thing you can use
> on
> your own subs by prototyping them with a &. See perlsub(1):
>
> An & requires an anonymous subroutine, which, if passed as
> the first argument, does not require the "sub" keyword or a
> subsequent comma. A * does whatever it has to do to turn
> the argument into a reference to a symbol table entry.
>
> The filehandle with no comma immediately after print is referred to in
> some
> parts of the documentation as an "indirect object".
Thanks, Alan. I looked up and reread the prototype section.
Things seem to be getting murkier and murkier. Look at the following
problems, I discovered.
1) sub mygrep (&@) {}; mygrep ({; -d $_ } @ARGV);
and got a syntax error. Recall from the earlier posts that this syntax
works for grep(). This is more fuel for the bug report, I guess.
2) I typed in the example from Camel p120 (a replementation of grep
using the (&@) prototype) and tried some test cases.
#!/usr/local/bin/perl -w
sub mygrep (&@) {
my $coderef = shift();
my @result;
foreach $_ (@_) {
push(@result, $_) if &$coderef;
}
@result;
}
grep sub { print(" grep <$_>\n") }, (1, 2, 3);
mygrep sub { print("mygrep <$_>\n") }, (1, 2, 3);
Running this produces:
mygrep <1>
mygrep <2>
mygrep <3>
So, when the first argument is an anonymous sub, then mygrep() evals it,
but grep() doesn't.
3) In the same example as above, leaving off the "sub" and the comma
produces a prototype error for grep() "Type of arg 1 to main::mygrep
must be block (not list)", but works properly for mygrep().
I'm running 5.00503 on cygwin32.
So,
1) How does grep distinguish between an EXPR and a BLOCK. I appears
that it's not related to the comma, but it also appears that it's not
related to the difference in types between an expression and an
anonymous sub, since apparently you can't really pass an anonymous sub
to grep(). So, what's the full scoop? Does the parser have special
code just to handle grep()? Is the first argument to grep() just passed
as the first entry in @_, as it is for mygrep()? Can a mygrep()
function be created which exactly mirrors grep()?
2) How is this related, if at all, to the optional first argument to
print() which requires no following comma? How is this passed to
print() -- as the first entry in @_? Does the parser have special code
to handle print()? Can a myprint() function be created which exactly
mirrors print()? I see in the newsgroup archives for 9/21/99 a short
discussion of prototyping print() but there weren't any wizards
participating. Anyone have a link to another discussion?
--
John Wiersba
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 11 Oct 1999 20:06:56 GMT
From: jrw32982@my-deja.com
Subject: Re: parenthesizing arguments to grep - BLOCK form
Message-Id: <7ttg0k$cq9$1@nnrp1.deja.com>
In article <MPG.126bcd4c9bbeec5f98a070@nntp.hpl.hp.com>,
lr@hpl.hp.com (Larry Rosler) wrote:
> grep(BLOCK, ...)
>
>
> > BTW, what do you call those thingies and what exactly is their
> > syntactic
> > status.
>
> See above.
I meant the thingies which don't require/allow a comma after them.
Other arguments are collected into a list, but these weird thingies
apparently can't be collected into the argument list (at least for
print() they can't) but instead need to be distinguished
syntactically. If they don't need to be distinguished syntactically,
then there would be no need for error messages like "No comma allowed
after filehandle".
-- John Wiersba
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 11 Oct 1999 12:46:51 -0700
From: Samay <samay1NOsaSPAM@hotmail.com.invalid>
Subject: Perl Interview Question:
Message-Id: <000b8d9b.709752c1@usw-ex0102-016.remarq.com>
Simple See if you can test yourself:
$x=2;
foreach $x (1..10){
print $x;
}
print $x;
Question:What's the last value of $x.
* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!
------------------------------
Date: Mon, 11 Oct 1999 12:29:42 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: Perl lite
Message-Id: <38023AA6.B7426DD9@cisco.com>
John Kristian wrote:
> The HTML documentation uses a lot of disk space;
> eliminating it would yield a smaller footprint.
How can HTML docs affect footprint ?
--
------------------------------
Date: 11 Oct 1999 15:02:31 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Perl lite
Message-Id: <slrn804gi9.gep.abigail@alexandra.delanet.com>
John Kristian (kristian@netscape.com) wrote on MMCCXXXII September
MCMXCIII in <URL:news:38022B7C.2B2C790F@netscape.com>:
^^ How can I make Perl occupy less disk space?
^^ I mean without making it useless, of course.
^^
^^ The HTML documentation uses a lot of disk space;
^^ eliminating it would yield a smaller footprint.
^^ I thought I might replace it with links to the Web.
^^ Have you tried something similar?
No. du -k /opt/perl yields 25Mb, and that's including the gzipped
tar file and site_perl. Only about 10% of that is taken by
/opt/perl/man/man1.
I wouldn't want to delete any of it. Disk space isn't that expensive
nowadays. I'm sure you have other junk you can delete. ;-)
Abigail
--
perl -we 'print q{print q{print q{print q{print q{print q{print q{print q{print
qq{Just Another Perl Hacker\n}}}}}}}}}' |\
perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 11 Oct 1999 20:21:52 GMT
From: itsme9905@aol.comnojunk (ItsMe9905)
Subject: Re: Perl lite
Message-Id: <19991011162152.12945.00000141@ng-cc1.aol.com>
Sure, you could probably remove the docs, that's is if you can foresee never,
ever having a need to refer to them.
------------------------------
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 1042
**************************************