[19020] in Perl-Users-Digest
Perl-Users Digest, Issue: 1215 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 29 03:05:59 2001
Date: Fri, 29 Jun 2001 00:05:12 -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: <993798311-v10-i1215@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 29 Jun 2001 Volume: 10 Number: 1215
Today's topics:
Re: Client/Server question (David Efflandt)
Code Review Needed! (Dave Hoover)
Re: Code Review Needed! (Tad McClellan)
coding technique - how would you do this? (TuNNe|ing)
Re: coding technique - how would you do this? <godzilla@stomp.stomp.tokyo>
Re: coding technique - how would you do this? (TuNNe|ing)
Re: converting shell "sort" command to perl.. <goldbb2@earthlink.net>
Re: Create unique file in dir? <jurgenex@hotmail.com>
Re: How to get env $HOME use perl (Joe Smith)
Re: is there a way to look ahead/behind in a foreach (@ <nospam@cfl.rr.com>
Re: is there a way to look ahead/behind in a foreach (@ (Logan Shaw)
Naming a hash <justin.devanandan.allegakoen@intel.com>
Re: Naming a hash (Bernard El-Hagin)
Re: New To Perl--Regex Question <goldbb2@earthlink.net>
Re: Opening files on the Mac? (newbie) <bigiain@mightymedia.com.au>
Re: Opening files on the Mac? (newbie) <goldbb2@earthlink.net>
Re: Opening files on the Mac? (newbie) <bigiain@mightymedia.com.au>
Re: Opening files on the Mac? (newbie) <sumus@aut.dk>
Re: passing variables the 'right' way <patelnavin@icenet.net>
Perl from VXML <howard@brazee.net>
Re: Perl from VXML (Tad McClellan)
Re: problems with mod_perl <snefski@hotmail.com>
Re: Processing command line <goldbb2@earthlink.net>
Re: pull out last line in a text file (Logan Shaw)
Re: pull out last line in a text file <krahnj@acm.org>
Re: pull out last line in a text file <Patrick_member@newsguy.com>
Re: pull out last line in a text file (Damian James)
Regexp problem <jan@klaverstijn.nl>
Re: Split without delimiter? <joe+usenet@sunstarsys.com>
Re: turbo perl (Tad McClellan)
Re: turbo perl (Rafael Garcia-Suarez)
Re: turbo perl (Rafael Garcia-Suarez)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 29 Jun 2001 04:39:50 +0000 (UTC)
From: see-sig@from.invalid (David Efflandt)
Subject: Re: Client/Server question
Message-Id: <slrn9jo1km.1t8.see-sig@typhoon.xnet.com>
On Thu, 28 Jun 2001, Andrew Paul Gorton <gortona@cs.man.ac.uk> wrote:
> Hi everyone,
>
> I am using IO::Socket to establish a client/server to monitor system
> resources on hosts and report the results to a Tk interface.
>
> The problem I am having is sending a list of commands and arguments to
> the server from the client and then getting the results back.
>
> On the client side I have the code to establish the connection and then
> request commands from the server:
>
> print $sock "USER:$parameter";
> print scalar <$sock>;
>
> print $sock "CPU";
> print scalar <$sock>;
> ...
You have no newline ("\n") above. Even if you unbuffer $sock, <$new_sock>
would block until it receives an input record separator (\n by default or
whatever $/ is set to) or the socket is closed. So in your case the
server does nothing until the client closes the socket (eof), therefore,
the client never gets any response. Then look at whether the server
response ends with a newline so the client does not block the response
waiting for the input record separator. Depending upon what you are
doing, you man then need to use chomp somewhere.
> And on the server side I have:
>
> while ($new_sock = $sock->accept()) {
> $new_sock->autoflush(1);
>
> while (defined($buf = <$new_sock>)){
>
> @para = split(/:/, $buf);
>
> if ($para[0] eq "USER"){
> print
> ($new_sock&Details::details($para[1]);#package
> }
>
> elsif ($para[0] eq "CPU"){
> print
> ($new_sock &Cpu::CPU_details);
> }
> ...
> }
> }
> But it just hangs. I have only been learning PERL for a few weeks so
> any help will be much appreciated.
>
> Sorry for the long question. Cheers
--
David Efflandt (Reply-To is valid) http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: 28 Jun 2001 20:23:05 -0700
From: redsquirreldesign@yahoo.com (Dave Hoover)
Subject: Code Review Needed!
Message-Id: <812589bb.0106281923.4a78bc90@posting.google.com>
I would greatly appreciate ANY feedback anyone could provide. The
following page will provide details and a link to download the
tarball.
http://www.redsquirreldesign.com/soapbox
TIA
--
Dave Hoover
"Twice blessed is help unlooked for." --Tolkien
http://www.redsquirreldesign.com/dave
------------------------------
Date: Fri, 29 Jun 2001 01:38:15 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Code Review Needed!
Message-Id: <slrn9jo527.msq.tadmc@tadmc26.august.net>
Dave Hoover <redsquirreldesign@yahoo.com> wrote:
>I would greatly appreciate ANY feedback anyone could provide. The
>following page will provide details and a link to download the
>tarball.
>
>http://www.redsquirreldesign.com/soapbox
If the file is named 'soapbox.tar.gz', folks expect it to
create a directory named 'soapbox' to put its files in.
Your packaging would have wiped out my INSTALL file if one
should have happened to be in my current directory...
> #!/usr/bin/perl -w
Gak! If you are taking form input, you really ought to have
taint checking turned on and think when you untaint the data.
(perldoc perlsec):
#!/usr/bin/perl -wT
> # Load the keywords used
> my ($terms, @terms);
> if ($s->{terms}) {
> @terms = @{$s->{terms}};
> for (@terms) { $terms .= "$_ " }
You do not need the @terms temporary variable, and Perl has
a function for doing what I think you are trying to do:
if ($s->{terms}) {
$terms = join ' ', @{$s->{terms}};
> chomp($terms); # for some reason chomp wasn't working here
^^^^^^^^^^^^^^^^^^^
Yes it was. chomp() removes a newline if the string ends with one,
else it does nothing. There cannot possibly be a newline at the
end of any of your strings, because you tack a space onto the
end each time. chomp() does nothing, like it is supposed to.
If you were trying to remove the extra space on the end, then
$terms =~ s/ $//; # join() doesn't have that problem
If you wanted to strip all newline characters:
$terms =~ tr/\n//d;
Other than that, the code in main.cgi looked pretty good.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 29 Jun 2001 01:41:35 GMT
From: troll@gimptroll.com (TuNNe|ing)
Subject: coding technique - how would you do this?
Message-Id: <3b3bf546.1539767@news>
Hello.
Bear with me, this may appear to be a CGI question, but I feel it
drives at the root of my perly technique.
Ok. I have two templates that contain HTML.
To create "dynamic" content I use variables in my templates.
template.cgi contains the HTML for a "dynamic" table.
main.cgi contains the HTML for the main page.
manager.cgi decides which variable($tableone or $tabletwo) content
from template.cgi goes into the variable in main.cgi($dynamic)
Now in my perl script that would manage(manager.cgi) these files I do
something like this.
*Assuming manager.cgi decodes the URL using the GET method and all
form data is stored in a hash called %form via a subroutine called
getForm().
--begin manager.cgi--
require "template.cgi";
getForm(\%form);
if ($form{GUI} eq "redirect") {
$dynamic = "$tableone";
}
elsif ($form{GUI} eq "compose") {
$dynamic = "$tabletwo";
}
require "main.cgi";
print "Content-type: text/html\n\n";
print $main;
exit;
--end manager.cgi--
--begin template.cgi--
$tableone = qq(
<table>
table1
</table>
);
$tabletwo = qq(
<table>
table1
</table>
);
1;
--end template.cgi--
--begin main.cgi--
$main = qq(
$dynamic
);
1;
--end main.cgi--
The above code is probably does NOT work.
I feel like I am abusing the _require_ statement. Is there another way
to do this?
Regards,
Jason
------------------------------
Date: Thu, 28 Jun 2001 19:53:10 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: coding technique - how would you do this?
Message-Id: <3B3BED96.B3AD3A78@stomp.stomp.tokyo>
TuNNe|ing wrote:
(snipped)
> The above code is probably does NOT work.
What benefit do you attain by writing code
and never testing this code?
How rude of you to drop in here, post code
which you don't know if it works or not,
then asking others to write code for you.
I can't speak for others but I am certain
I do not have "Slave Girl" tattooed across
my dark skin forehead.
Godzilla!
------------------------------
Date: Fri, 29 Jun 2001 03:00:10 GMT
From: troll@gimptroll.com (TuNNe|ing)
Subject: Re: coding technique - how would you do this?
Message-Id: <3b3c0cda.7576890@news>
umm...dude. i meant the sample code included in the message
might not work being i wrote it for demonstration purposes.
for a working model see
http://www.gimptroll.com/cgi-bin/gtmailer/GTmailer.cgi
Regards,
Jason
aka Slave Girl Spanker
On Thu, 28 Jun 2001 19:53:10 -0700, "Godzilla!"
<godzilla@stomp.stomp.tokyo> wrote:
>TuNNe|ing wrote:
>
>(snipped)
>
>> The above code is probably does NOT work.
>
>What benefit do you attain by writing code
>and never testing this code?
>
>How rude of you to drop in here, post code
>which you don't know if it works or not,
>then asking others to write code for you.
>
>I can't speak for others but I am certain
>I do not have "Slave Girl" tattooed across
>my dark skin forehead.
>
>
>Godzilla!
------------------------------
Date: Fri, 29 Jun 2001 02:03:28 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: converting shell "sort" command to perl..
Message-Id: <3B3C1A30.54DC5E6@earthlink.net>
Patrick Erler wrote:
>
> hello!
>
> i have a small shell script which sorts log files for me.. from the
> usenet i got a sort command to do it once, i never tried to understand
> what it does (and i wasn't that interrested in it anyway) it just
> worked...
>
> now i want to convert the script to perl, no big problem, but this
> command i just don't get converted:
>
> sort -k 4.9b,4.13n -k 4.5b,4.7M -k 4.2b,4.3n -k4.14b,4.15n
> -k 4.17b,4.18n -k 4.20b,4.21n
>
> what it sorts is a simple apache log like this:
> 213.83.52.132 - - [28/Jun/2001:20:29:43 +0200] "GET / HTTP/1.0" 200
> 3392 "-" "check_http/1.32.2.6 (netsaint-plugins 1.2.9-4)"
>
> ok, i could call the shell but i really would like to do it in perl...
#! perl -w
use strict;
@ARGV <= 1 or die "Usage:\n\t$0 [logfile]\n";
my %mon;
@mon{qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)} = (0..11);
my $ofh;
my $stabilizer = 0;
print $ofh substr $_, 11 for (
sort
map {
# 213.83.52.132 - - [28/Jun/2001:20:29:43 stuff
m/^\S* \S* \S* (\S*)/;
my @date = unpack "xa2xa3xa4xa2xa2xa2", $1;
pack "ncccccNa*",
$date[2], $mon{$date[1]}, @date[0,3,4,5],
++$stabilizer, $_;
} do {{ # double leftbrace to make a block
($ifh, $ofh) = (*STDIN, *STDOUT), last if @ARGV == 0;
open my $ifh, "<", $ARGV[0] # my $ifh closed at end of do-block.
or die "Could not open $ARGV[0] for r: $!\n";
rename( $ARGV[0], $ARGV[0] . ".bak" )
or die "Could not rename $ARGV[0] to $ARGV[0].bak: $!\n";
open $ofh, ">", $ARGV[0] # note there is no "my" here.
or die "Could not open $ARGV[0] for w: $!\n";
} # end of block; "last" from above skips to here.
<$ifh>;
};
close $ofh or die "Could close $ARGV[0]: $!\n" if @ARGV == 1;
__END__
I could have used Time::Local rather than packing the date components as
bytes, but there is no need to bring it in, since it isn't really
needed.
Note that this code is untested.
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Thu, 28 Jun 2001 21:49:41 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Create unique file in dir?
Message-Id: <3b3c08f0@news.microsoft.com>
"Craig Berry" <cberry@cinenet.net> wrote in message
news:tjn5cm42nfgafd@corp.supernews.com...
> Anybody have suggestions on how to create a unique file in a directory,
A combination of the epoch time together with the process ID of the Perl
program should usually do just fine.
jue
------------------------------
Date: Fri, 29 Jun 2001 06:57:49 +0000 (UTC)
From: inwap@best.com (Joe Smith)
Subject: Re: How to get env $HOME use perl
Message-Id: <9hh8td$dav$1@nntp1.ba.best.com>
In article <34UZ6.15070$cF.329723@news1.nokia.com>,
Wang Feiyun-Arthur <feiyun-arthur.wang@nokia.com> wrote:
>In Perl file.
>
>How can I get my env $HOME
>
>I tried
>
>$home=$HOME;
>and
>$home=`echo $HOME`;
Check the Perl manual. Look for the description of the %ENV array.
$home = $ENV{HOME};
-Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.
------------------------------
Date: Fri, 29 Jun 2001 04:10:55 GMT
From: tuxy <nospam@cfl.rr.com>
Subject: Re: is there a way to look ahead/behind in a foreach (@l)?
Message-Id: <3B3C01DB.35C36395@cfl.rr.com>
> $::i is an abbreviation for $main::i
>
OK thanks, and then @::myarray is the same as @main::myarray? Curious.
Sort of undocumented isn't it? I've read the package sections in Camel
pretty well many times and don't recall seeing anyting like that. How do
you guys "find" these things? I didn;t learn how to access other array
elements very well which was my original question, but this ws an
interesting relelvation, another one with which to dazzel my co-workers
:)
Open Source less than 1 month AWAY! YES!
-tux
------------------------------
Date: 28 Jun 2001 23:39:34 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: is there a way to look ahead/behind in a foreach (@l)?
Message-Id: <9hh0q6$lg6$1@charity.cs.utexas.edu>
In article <3B3C01DB.35C36395@cfl.rr.com>, tuxy <nospam@cfl.rr.com> wrote:
>
>> $::i is an abbreviation for $main::i
>>
>
>OK thanks, and then @::myarray is the same as @main::myarray? Curious.
>Sort of undocumented isn't it?
"perldoc perlmod" says:
If the package
name is null, the `main' package is assumed. That is,
`$::sail' is equivalent to `$main::sail'.
I did a "perldoc perlvar" first, which turns out to have been the wrong
place to look, but it at least told me to "see the perlmod manpage".
So, while you might have to dig for it a little (the digging will be
made easier if you read manual pages with a tool that allows you to
search for "::"), it is there in the documentation.
- Logan
--
my your his her our their _its_
I'm you're he's she's we're they're _it's_
------------------------------
Date: Fri, 29 Jun 2001 14:27:09 +0800
From: "Just in" <justin.devanandan.allegakoen@intel.com>
Subject: Naming a hash
Message-Id: <9hh740$67t@news.or.intel.com>
Dear group,
Suppose I was in a loop, and I wanted to push some values into a hash, but I
wanted the hash to have a different name for each iteration of the loop. i.e
how can I do this:-
for ($a = 0; $a <= $#SomeArray; $a++)
{
# do something to get data here
$NewHash$a{$Var} = $Val;
}
Obviously this wont work, and variations of the theme (that I have
attempted), dont work either.
I would really appreciate if someone were to enlighten me.
Thanks
Just (I dont know nuts) in
------------------------------
Date: Fri, 29 Jun 2001 06:40:13 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Naming a hash
Message-Id: <slrn9jo8aq.112.bernard.el-hagin@gdndev25.lido-tech>
On Fri, 29 Jun 2001 14:27:09 +0800, Just in
<justin.devanandan.allegakoen@intel.com> wrote:
>Dear group,
>
>Suppose I was in a loop, and I wanted to push some values into a hash, but I
>wanted the hash to have a different name for each iteration of the loop. i.e
>how can I do this:-
>
>for ($a = 0; $a <= $#SomeArray; $a++)
>{
> # do something to get data here
>
> $NewHash$a{$Var} = $Val;
>}
>
>Obviously this wont work, and variations of the theme (that I have
>attempted), dont work either.
Instead of creating a new name with each iteration why not
do something like:
for( my $a = 0; $a <= $#some_array; $a++ ){
$hash{$a}{$var} = $val;
}
That way you don't need symbolic refs (which is what you're asking for
even if you don't know it) which are evil.
Cheers,
Bernard
--
perl -l54e's yyw q q tvmrx "h\ywx ersxliv zivp legoiv"qiy;y #a-zA-Z#d-gu-z#
chefghijklmnopqrstuvwxyzcJab-def-uPwxyzc;s j j s u u s t t s r r s
ppevalpereeteueje'
------------------------------
Date: Fri, 29 Jun 2001 00:11:18 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: New To Perl--Regex Question
Message-Id: <3B3BFFE6.3D6DAB18@earthlink.net>
JR wrote:
>
> I'm new to Perl, so please forgive this very simple question. I'm
> trying to figure out what type of regular expression to 'grab' several
> lines of data and push them into an array. For instance, if I have a
> file that has the following and the pattern I want to find is
> "pattern":
>
> line 1 #pattern not found (single line)
> line 2 #pattern not found (single line)
> line 3 "pattern.... #pattern found (multiple lines)
> line 4 ..........." #the pattern is not on this line, but because it
> is on the previous line and that line spans several
> lines, I want all subsequent lines to match until
> the next pattern for which I am searching is found.
>
> For example, if I'm trying to match the word dog (and include data
> through to the next occurance of where information for dog is not
> found (which would be four lines down, where the 'z' is, in this
> instance):
>
> 1) xxxxxxxxxxxxxxxxxxxxxxxxxx
> 2) yyyyyyyyyyyyyyyyyyyyyyyyyy
> 3) dog
> ddddddddd
> dddddddddd
> ddddddddddd
> 4) zzzzzzzzzzzzzzzzzzzzzzzzzz
>
> The data I am trying to match against is separated by line numbers, as
> above, so that should make it easier, but I haven't found a way to
> make it work, as of yet. Listed below is the code that I have
> created, which almost works. Any advice anyone could offer would be
> greatly appreciated. Thank you very much.
>
> #!/usr/local/bin/perl -w
> use strict;
>
> my ( @getdata, $getdata, @holddata, $holddata, @file_reference,
> @date_submitted,
> @type_of_change, @state_code, @county_code, @area, @mcd_place,
> @political_desc, @desc_of_change, @date_of_change, @additional_info,
> @junkData,
> $area, $mcd_place, $getdata2, @temp, $temp, @make_dp,
> $make_dp, $junkData );
Do you really and truly need all of these variables? Also, wouldn't it
be much simpler to declare them where you first use them?
>
> open(GOOD,"dps_cluttered.txt") || die "Cannot open new_dps.txt: $!";
> @getdata = <GOOD>;
> chomp @getdata;
> close ( GOOD );
my @chunks = split m[(?=^\d+\)\ ]m, # split just before line #s
do { local $/ = undef;
open( my $fh, "<", "dps_cluttered.txt" )
or die "Could not open dps_cluttered.txt: $!\n";
<$fh>; };
> foreach $getdata ( @getdata ) {
> undef $/;
What is undef $/ supposed to accomplish? Anyway, going with the
principle of declaring variables over the smallest scope, this would be:
foreach my $chunk ( @chunks ) {
> if ( $getdata =~ /File Reference/i ) {
> push ( @make_dp, $getdata );
> }
> elsif ( $getdata =~ /Date Submitted/i ) {
> push ( @make_dp, $getdata );
> }
> elsif ( $getdata =~ /Type of Change/i ) {
> push ( @make_dp, $getdata );
> }
> elsif ( $getdata =~ /State-code/i ) {
> push ( @make_dp, $getdata );
> }
> elsif ( $getdata =~ /County-code/i ) {
> push ( @make_dp, $getdata );
> }
> elsif ( $getdata =~ /Area/ ) {
> push ( @make_dp, $getdata );
> }
> elsif ( $getdata =~ /MCD-place/i ) {
> push ( @make_dp, $getdata );
> }
> elsif ( $getdata =~ /Political Desc./i ) {
> push ( @make_dp, $getdata )
> }
> elsif ( $getdata =~ /Desc. of change/i ) {
> push ( @make_dp, $getdata );
> }
> elsif ( $getdata =~ /Date of change/i ) {
> push ( @make_dp, $getdata );
> }
> elsif ( $getdata =~ /Additional Info/i ) {
> push ( @make_dp, $getdata );
> }
if( $chunk =~ m[^\d+\)\ (
File\ Reference|
Date\ Submitted|
Type\ of\ Change|
State-code|
County-code|
Area|
MCD-place|
Political\ Desc\.|
Desc\.\ of\ change|
Date\ of\ change|
Additional\ Info)]ix )
{
push @make_dp, $chunk;
}
> else {
> push ( @junkData, $getdata );
> }
> }
>
> foreach $make_dp ( @make_dp ) {
> print "$make_dp\n";
> if ( $make_dp =~ /\(11\)/ ) {
> print "\t---\n\n"; #provide break at last line of DP
> }
> }
print foreach ( @make_dp );
# all elements of @make_dp still include their newlines.
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Fri, 29 Jun 2001 12:25:15 +1000
From: Iain Chalmers <bigiain@mightymedia.com.au>
Subject: Re: Opening files on the Mac? (newbie)
Message-Id: <bigiain-33F489.12251529062001@news.pacbell.net>
In article <3b3bc399.8665574@news.erols.com>, tiltonj@erols.com (Jay
Tilton) wrote:
> On 28 Jun 2001 16:10:31 -0700, mauer@pageweavers.com (Steve) wrote:
>
> >I have tried every permutation of the following:
> >
> >require 'StandardFile.pl'; #not sure what this does
> >open(TEXT,">/Macintosh HD/Applications/PERL/sampledata.txt") || die
> >"Couldn't open TEXT.\n";
> >
> >resulting in: "# Couldn't open TEXT." (file does exist...)
>
> Make it tell you the reason for failure with '$!'.
>
> open(TEXT,">/Macintosh HD/Applications/PERL/sampledata.txt")
> || die "Couldn't open TEXT: $!";
> ^^
> ^^
And, use the Mac path separator ":"
open(TEXT,">Macintosh HD:Applications:PERL:sampledata.txt")
|| die "Couldn't open TEXT: $!";
Read the "Macintosh specific features" bit from the MacPerl "help" menu.
cheers
Iain
------------------------------
Date: Thu, 28 Jun 2001 23:46:42 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Opening files on the Mac? (newbie)
Message-Id: <3B3BFA22.245CEBC1@earthlink.net>
Iain Chalmers wrote:
>
> In article <3b3bc399.8665574@news.erols.com>, tiltonj@erols.com (Jay
> Tilton) wrote:
>
> > On 28 Jun 2001 16:10:31 -0700, mauer@pageweavers.com (Steve) wrote:
> >
> > >I have tried every permutation of the following:
> > >
> > >require 'StandardFile.pl'; #not sure what this does
> > >open(TEXT,">/Macintosh HD/Applications/PERL/sampledata.txt") || die
> > >"Couldn't open TEXT.\n";
> > >
> > >resulting in: "# Couldn't open TEXT." (file does exist...)
> >
> > Make it tell you the reason for failure with '$!'.
> >
> > open(TEXT,">/Macintosh HD/Applications/PERL/sampledata.txt")
> > || die "Couldn't open TEXT: $!";
> > ^^
> > ^^
>
> And, use the Mac path separator ":"
>
> open(TEXT,">Macintosh HD:Applications:PERL:sampledata.txt")
> || die "Couldn't open TEXT: $!";
Shouldn't perl automatically translate / into : for you?
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Fri, 29 Jun 2001 13:48:49 +1000
From: Iain Chalmers <bigiain@mightymedia.com.au>
Subject: Re: Opening files on the Mac? (newbie)
Message-Id: <bigiain-449E95.13484929062001@news.pacbell.net>
In article <3B3BFA22.245CEBC1@earthlink.net>, Benjamin Goldberg
<goldbb2@earthlink.net> wrote:
> Iain Chalmers wrote:
> >
> > In article <3b3bc399.8665574@news.erols.com>, tiltonj@erols.com (Jay
> > Tilton) wrote:
> >
> > > On 28 Jun 2001 16:10:31 -0700, mauer@pageweavers.com (Steve) wrote:
<snip>
> > > open(TEXT,">/Macintosh HD/Applications/PERL/sampledata.txt")
> > > || die "Couldn't open TEXT: $!";
> > > ^^
> > > ^^
> >
> > And, use the Mac path separator ":"
> >
> > open(TEXT,">Macintosh HD:Applications:PERL:sampledata.txt")
> > || die "Couldn't open TEXT: $!";
>
> Shouldn't perl automatically translate / into : for you?
Nope, I'm _allowed_ to have a file on my Mac called "foo/baz/bah"...
Iain
------------------------------
Date: 29 Jun 2001 08:54:02 +0200
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: Opening files on the Mac? (newbie)
Message-Id: <m23d8jrd2t.fsf@pocketlife.dk>
Iain Chalmers <bigiain@mightymedia.com.au> writes:
> And, use the Mac path separator ":"
Unless you're on MacOS X.
--
Jakob
------------------------------
Date: Fri, 29 Jun 2001 11:15:42 +0530
From: "Aman Patel" <patelnavin@icenet.net>
Subject: Re: passing variables the 'right' way
Message-Id: <9hh4lh$ea0pf$1@ID-93885.news.dfncis.de>
> We all want to write code in a way that we consider easy to understand.
But
> we have different preferences. To me the shifting game hurts my feelings
> because it seems foolish to alter @_ if you don't need the altered version
> for some specific purpose.
>
> So shifting blurs the semantic in my view, because it kinda indicates
> that you want to alter @_ when that's not really the case at all.
>
I cant agree with you more, actually when i had your reply to this topic
earlier, my style changed, and i was doing $_[0] when i wanted to just read
from the passed variables. I stopped using my $x =shift, although it might
be faster or otherwise.
> Maybe that's just me.
and me too :)
> > For me, it's visually cleaner and makes maintenance easier. It's more
> > flexible too:
> >
> > sub mysub {
> > my $alpha = shift;
> > my @beta = map {$_ + 1} split /:/, shift;
> > my $gamma = shift || 42;
>
> Fair enough - I can see your point, but in my opinion getting the params
> in place at first and then using them is _much_ clearer and _much_ less
> vulnerable to change:
>
> sub mysub {
> my ( $alpha, $betafields, $gamma ) = @_;
> my @beta = map { $_ + 1 } split /:/, $betafields;
> my $gamma ||= 42;
Well I say if you really wanna modify your code, I would still use the shift
construct, to me it looks much nicer than putting list of variables and
assiging @_ to them. Although I have no good reason to shorten or use the
modified @_, it still appeals to me since 'shift' was the first thing i
learned about accepting arguments in a subroutine.
Aman
------------------------------
Date: Thu, 28 Jun 2001 19:31:00 -0600
From: Howard Brazee <howard@brazee.net>
Subject: Perl from VXML
Message-Id: <3B3BDA54.A4BE425C@brazee.net>
I am trying out some VXML, calling a Perl script written to be called by
HTML. I am not familiar with Perl, but the VXML debugger is finding a
mismatched tag, leading me to infer that I am receiving some HTML code
back.
I changed print "<html><body>Unknown Request Method.</html><body>","\n"
;
To print "<html><body>Unknown Request
Method.<body></html>","\n" ;
because XML is fussy about closing inner tags before outer tags.
I am not sure how this works. I am an old CoBOL programmer and this is
all new to me. My VXML command is:
<submit next="XXX" method="post" namelist="userid userpw progname
timestamp jsverify inst frames" />
(where XXX is the name of the .CGI file) and I know that the variables
are all filled out. I also know that that script can be seen from the
web, even if it is not understood. I think it is running the correct
version of the script, but I am not sure.
What I would like to do is to see what is being passed back to my VXML.
I run VXML from dialing up to TellMe, and it runs it using my phone
input. This is not a visual environment.
I have added commands such as what is between the #HJB comments:
# Begin Main Program
# Initialize Globals
#HJB start
use diagnostics -verbose;
enable diagnostics;
open stdout, ">debughjb";
open stderr, ">myerror";
#HJB end
I don’t see anything different. I was expecting to see two new files in
the directory containing the Perl script, but no HTML being passed back
to the VXML via the PRINT command
------------------------------
Date: Fri, 29 Jun 2001 00:51:53 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl from VXML
Message-Id: <slrn9jo2b9.msq.tadmc@tadmc26.august.net>
Howard Brazee <howard@brazee.net> wrote:
>I am trying out some VXML,
What is VXML?
Is it XML of some flavor or another?
>calling a Perl script written to be called by
>HTML.
CGI programs are called by www *servers* (not by browsers).
Which computer your program is running on is an important
thing to know.
>I am not familiar with Perl, but the VXML debugger is finding a
>mismatched tag, leading me to infer that I am receiving some HTML code
>back.
>
>I changed print "<html><body>Unknown Request Method.</html><body>","\n"
^^
^^
>;
>
> To print "<html><body>Unknown Request
>Method.<body></html>","\n" ;
^^
^^
^^ </body>
>because XML is fussy about closing inner tags before outer tags.
That can't be the reason, because you _still_ haven't closed
any <body> sections, you just opened a second one. :-)
>I am not sure how this works.
That will make things hard to troubleshoot :-) :-)
>I am an old CoBOL programmer and this is
>all new to me.
"this" is actually "these".
Folks just starting with CGI programming are often new to
several different domains all at once. This can easily
lead to overload.
My advice it to slow down and try and learn them only one
or two at a time.
These may not apply to you, if not then just ignore me.
1) Usenet - what newsgroups exist, netiquette for posting...
2) Unix - home system is Bill's, ISP's web server in *nix.
3) Perl - and often new to programming in general too
4) CGI - programming an application in the CGI environment
Try and learn programming/Perl first. You can do this on your
home machine without an ISP. Perl is free, just download and
install it.
First get comfortable writing programs that run from the
command line before adding the complications of a particular
application area (CGI).
Then use the CGI module for your CGI programs, and you will be
able to test it from the command line locally, again with no
web server involved.
After you get your CGI program working from the command line,
_then_ is when you need to know the particulars of how your
web servers is setup. You should ask your provider to tell
you how they have set things up. Also ask them about access
to the web server's error logs.
You might also get a free web server to run locally.
There are newsgroups for discussing servers and the CGI
environment:
comp.infosystems.www.authoring.cgi
comp.infosystems.www.servers.mac
comp.infosystems.www.servers.misc
comp.infosystems.www.servers.ms-windows
comp.infosystems.www.servers.unix
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 29 Jun 2001 08:51:12 +0200
From: S.E.Franke <snefski@hotmail.com>
Subject: Re: problems with mod_perl
Message-Id: <MPG.15a643c6dc816ce1989687@news.cistron.nl>
In article <9hfp4k$l9k$1@canopus.cc.umanitoba.ca>,
randy@theoryx5.uwinnipeg.ca says...
> In comp.lang.perl.misc, S.E.Franke <snefski@hotmail.com> wrote:
>
> > I want to use mod_perl, but I couldn't find a appropriate newsgroup for
> > my problem, so I'll try it here ;-)
>
> There's a mailing list for mod_perl - see http://perl.apache.org/
> for subscription details.
>
> > I have configured Apache and the mod_perl is working ok.I have seen a lot
> > of examples on the net, but I'm stuck here with a problem.
> > My script uses a Logger (Logger.pm) object, $lv_Logger.
> > I use sigHandlers in my script, and in the sub that handles the
> > sighandlers, I use the logger object.
> > The problems are with the logger object in the sub:
> > Variable $lv_Logger will not stay shared .........
> [ ... ]
> The mod_perl guide at http://perl.apache.org/guide/ has a discussion
> of the "variable will not stayed shared ..." problem.
>
> best regards,
> randy kobes
>
I know,....I've read it, but I've problems to translate the solution to
my problem.....
------------------------------
Date: Thu, 28 Jun 2001 23:49:49 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Processing command line
Message-Id: <3B3BFADD.4D6CDD5E@earthlink.net>
Swanthog wrote:
>
> Hi all,
>
> I'm using GetOpt::Long and want to parse a command switch like:
> >script.pl --host host_1 host_2 host_3 host_n
>
> Using GetOpt I only get host_1. I can see the other hosts in @ARGV but
> I really need a way to know that they were passed with the --host
> switch.
>
> Any ideas on how to do this? Keep in mind that the host names can be
> just about anything and are not limited to the host_n format I
> illustrated above.
Type the commandline as:
script.pl --host host_1,host_2,host_3,host_n
And then split on commas.
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: 28 Jun 2001 20:09:04 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: pull out last line in a text file
Message-Id: <9hgkfg$kse$1@charity.cs.utexas.edu>
In article <9hgjl1$kqs$1@charity.cs.utexas.edu>,
Logan Shaw <logan@cs.utexas.edu> wrote:
>In article <9hgfbe01ehm@drn.newsguy.com>,
>Patrick Flaherty <Patrick_member@newsguy.com> wrote:
>>How, in Perl, do I pull out the last line (or lines plural as in tail) of a text
>>file?
>
>Here's the quick and dirty way:
Oops, I forgot to give the obfuscated version:
print @{[<>]}[-3 .. -1];
(That prints the last three lines.)
- Logan
--
my your his her our their _its_
I'm you're he's she's we're they're _it's_
------------------------------
Date: Fri, 29 Jun 2001 01:13:18 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: pull out last line in a text file
Message-Id: <3B3BD671.E5CF4CB9@acm.org>
Patrick Flaherty wrote:
>
> Hello,
>
> How, in Perl, do I pull out the last line (or lines plural as in tail) of a text
> file?
my @lines = `tail -2 $file`; # :-)
John
--
use Perl;
program
fulfillment
------------------------------
Date: 28 Jun 2001 20:50:19 -0700
From: Patrick Flaherty <Patrick_member@newsguy.com>
Subject: Re: pull out last line in a text file
Message-Id: <9hgttr0bot@drn.newsguy.com>
Ah. Very nice.
I wrote something far more verbose (but illuminating). And as I learn more of
Perl, it strikes me that the approach to the inner circle is marked by _less_
not more code.
pat
In article <9hgkfg$kse$1@charity.cs.utexas.edu>, logan@cs.utexas.edu says...
>
>In article <9hgjl1$kqs$1@charity.cs.utexas.edu>,
>Logan Shaw <logan@cs.utexas.edu> wrote:
>>In article <9hgfbe01ehm@drn.newsguy.com>,
>>Patrick Flaherty <Patrick_member@newsguy.com> wrote:
>>>How, in Perl, do I pull out the last line (or lines plural as in tail) of a text
>>>file?
>>
>>Here's the quick and dirty way:
>
>Oops, I forgot to give the obfuscated version:
>
> print @{[<>]}[-3 .. -1];
>
>(That prints the last three lines.)
>
> - Logan
>--
>my your his her our their _its_
>I'm you're he's she's we're they're _it's_
------------------------------
Date: 29 Jun 2001 06:13:12 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: pull out last line in a text file
Message-Id: <slrn9jo71u.9fa.damian@puma.qimr.edu.au>
Logan Shaw chose 28 Jun 2001 20:09:04 -0500 to say this:
>In article <9hgjl1$kqs$1@charity.cs.utexas.edu>,
>Logan Shaw <logan@cs.utexas.edu> wrote:
>>In article <9hgfbe01ehm@drn.newsguy.com>,
>>Patrick Flaherty <Patrick_member@newsguy.com> wrote:
>>>How, in Perl, do I pull out the last line (or lines plural as in tail) of a text
>>>file?
>>
>>Here's the quick and dirty way:
>
>Oops, I forgot to give the obfuscated version:
>
> print @{[<>]}[-3 .. -1];
>
A way to do this without reading the *whole* file into RAM:
my @lines = ('') x 3;
shift @lines, push(@lines, $_) while <>;
print @lines;
Cheers,
Damian
--
@:=grep!($;+=m!$/|#!),split//,<DATA>;@;=0..$#:;while(@;){for($;=@;;--$;;)
{@;[$;,$:]=@;[$:,$;]if($:=rand$;+$|)!=$;}push@|,shift@;if$;[0]==@|;select
$,,$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker # rev 3.1 -- a JAPH in progress, I guess...
------------------------------
Date: Fri, 29 Jun 2001 09:00:05 +0200
From: "Jan Klaverstijn" <jan@klaverstijn.nl>
Subject: Regexp problem
Message-Id: <9hh929$1rb3$1@scavenger.euro.net>
Hi all,
This is what looks to me a simple regexp challenge but it drove me crazy.
I'm clearly a newbie at Perl regexp's. So now I turn to you.
What I want is to extract the date from a mail header line. The "Date:" line
comes can have an optional timezone at the end. That timezone must be
stripped, together with the Date: at the beginning.
Date: Mon, 25 Jun 2001 17:56:26 +0200 (CEST)
If the timezone was always there it would be easy: $date = $1 if
/^Date:\s(.+)\s(\(.+\))/;
But this fails to match when the timezone is not there.
Date: Mon, 25 Jun 2001 17:56:26 +0200
I thought making the timezonepart optional: (\(.+\))?. No luck.
How should I approach this to make it work with a single regular expression?
Regards,
Jan Klaverstijn
------------------------------
Date: 28 Jun 2001 21:17:11 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Split without delimiter?
Message-Id: <m3u210ozjc.fsf@mumonkan.sunstarsys.com>
johan@columbia.edu (Johan M. Andersen) writes:
> So I'm trying to take a really long line and split it into an arbitrary
> number of 8 character tokens. Right now, I do something like this...
>
> for($_=shift;$token=substr($_,$offset,8);$offset+=8) {
> # blah blah blah
> }
For fixed-width fields, unpack() is an obvious choice. See
% perldoc -f pack
% perldoc -f unpack
for details.
> Is there a better way to do this? I couldn't figure out how to make split
> work with no delimiters,
Not recommended, but since you asked ...
use 5.006;
my @fields = split /(??{ pos()%8 ? "^" : "" })/;
> or do a regexp that returns all the matches as an array. Thanks!
As suggested elsewhere,
my @fields = /.{1,8}/gs;
will work fine.
--
Joe Schaefer "Whatever you are, be a good one."
-- Abraham Lincoln
------------------------------
Date: Fri, 29 Jun 2001 01:53:08 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: turbo perl
Message-Id: <slrn9jo5u4.msq.tadmc@tadmc26.august.net>
Patrick Erler <perler@yahoo.com> wrote:
>the guy one floor above me in front of his /text mode/ turbo-c has a very
>handy online help system at his fingertips. /that's/ what i miss.
perldoc -f somefunction
>right now, when i'm not sure about the syntax of a perl function i print
>out variables, read books, read deja...
Perl ships with over 1000 "pages" of documentation written by
the same folks who work on the perl interpreter itself.
That should be your number one first stop when seeking info.
perldoc perldoc
to learn how to use perldoc.
>and i didn't even mention that debugger in turbo-c/pascal ;)
You also didn't mention the budget that paid the programmers
at Borland :-)
perldoc perldebug
for that one.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 29 Jun 2001 06:50:38 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: turbo perl
Message-Id: <slrn9jo9a9.5fl.rgarciasuarez@rafael.kazibao.net>
Patrick Erler wrote in comp.lang.perl.misc:
}
} the guy one floor above me in front of his /text mode/ turbo-c has a very
} handy online help system at his fingertips. /that's/ what i miss.
You missed perldoc. A /very/ /handy/ /text-mode/ help system.
At the prompt, enter "perldoc perldoc".
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: 29 Jun 2001 06:53:15 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: turbo perl
Message-Id: <slrn9jo9f6.5fl.rgarciasuarez@rafael.kazibao.net>
Buggs wrote in comp.lang.perl.misc:
....]
}
} Dunno, why you can't hack your .vimrc
} to map ctrl-f1 to perldoc -f print ...
Or:
:set kp=perldoc\ -f
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 1215
***************************************