[18482] in Perl-Users-Digest
Perl-Users Digest, Issue: 650 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 7 18:05:42 2001
Date: Sat, 7 Apr 2001 15:05:13 -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: <986681113-v10-i650@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 7 Apr 2001 Volume: 10 Number: 650
Today's topics:
Re: ? The best Perl book ? (---Pete---)
Re: ? The best Perl book ? (---Pete---)
Re: can Perl be used to draw tables or lines on the scr <wayne.keenan@ntlworld.com>
can somebody explain <alwin@worldmail.nl>
Re: can somebody explain (Steven Smolinski)
Re: can somebody explain <uri@sysarch.com>
Re: complaint about moderation of this group <bmb@ginger.libs.uga.edu>
Re: complaint about moderation of this group (---Pete---)
Re: cookie woes. <bmb@ginger.libs.uga.edu>
Re: Copy a directory structure <root@novastar.dtdns.net>
Re: inheritance within one file? <prlawrence@lehigh.edu>
Re: inheritance within one file? (Logan Shaw)
Re: inheritance within one file? <uri@sysarch.com>
Re: inheritance within one file? <uri@sysarch.com>
looking up Windows ODBC DSNs across the network <Patrick_member@newsguy.com>
Re: problem with making dirs! <webmaster@netdating.nl>
Re: problem with quoting or how to avoid \n at the the <info@java.seite.net>
Re: problem with quoting or how to avoid \n at the the <wuerz@yahoo.com>
Re: problem with quoting or how to avoid \n at the the (Tad McClellan)
Re: problem with quoting or how to avoid \n at the the (Logan Shaw)
Re: problem with quoting or how to avoid \n at the the <uri@sysarch.com>
Re: Radius detail File to csv <matt@webexplorers.com.au>
Re: Radius detail File to csv <bmb@ginger.libs.uga.edu>
Re: Radius detail File to csv <uri@sysarch.com>
sendmail script - got to be something simple <theXYZtenor@attXYZ.XYZnet>
Re: speed of strings and arrays? <dan@tuatha.sidhe.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 07 Apr 2001 20:35:01 GMT
From: bogus@erol.com (---Pete---)
Subject: Re: ? The best Perl book ?
Message-Id: <3acf764a.391032188@news.earthlink.net>
On Sat, 7 Apr 2001 19:19:49 +0200, "Dejan Bizinger"
<lists@brokerpal.com> wrote:
>I would like to start learning Perl so I would like you to recommend me some
>good book. I want to buy a book that starts explaining basics thru advanced
>programming. I have several picks like:
>Programming Perl - Larry Wall
>Learning Perl - Larry Wall
>Perl - The Complete Reference - McGraw-Hill
------
Dejan, for more details on your topic, check this NG for recent
topic: Hmmm... Which PERL Book Is Best Suited For This???
I'll summarize below for your particular inquiry.
You really need at least 2 books.
1.) "Programming Perl 3rd Edition" an O'Reily book -
by Wall, Christiansen, Orwant
2.) "Teach Yourself Perl in 24 Hours" (SAMS) by Clinton Pierce
The CAMEL book is what I was looking for; it's indexed well and
very comprehensive but it assumes a certain level of expertise.
I am a Visual Basic programmer and only about 3 weeks into
PERL. I'm finding that the combo of the SAMS book and the
CAMEL book work great because when I don't quite understand
what the CAMEL book is saying, I go to the SAMS book and it
clarifies the issue for me by using simpler and clearer instruction
and examples. These two books seem to a perfect combo for
someone of my level of expertise.
Dejan, be careful when purchasing 2 books on the same topic.
I do not recommend purchasing 2 books by the same author
becasue if you don't understand the way he explains something
in one book, it's very likely that his other book won't help either.
However, a book by a different author may explain the topic in
a manner that makes it clear as day.
---pete---
------------------------------
Date: Sat, 07 Apr 2001 20:43:38 GMT
From: bogus@erol.com (---Pete---)
Subject: Re: ? The best Perl book ?
Message-Id: <3acf7b5a.392328659@news.earthlink.net>
In previous posting, I forgot to mention, that
this book is the "CAMEL" book. It's the
one with the big camel on the cover.
1.) "Programming Perl 3rd Edition" an O'Reily book -
by Wall, Christiansen, Orwant (The CAMEL book).
---pete---
------------------------------
Date: Sat, 07 Apr 2001 20:16:25 +0100
From: "wayne.keenan" <wayne.keenan@ntlworld.com>
Subject: Re: can Perl be used to draw tables or lines on the screen in UNIX??
Message-Id: <3ACF6788.ACC35AB9@ntlworld.com>
hAWK wrote:
> If so, could you please direct me to a good tutorial site.
> Thanks
use Tk; (interactive GUI apps);
http://www.perl.com/pub/2001/03/gui.html
http://www.perlmonth.com/features/perl_tk/perl_tkstart.html?issue=1
use Gtk; (interactive GUI apps):
http://projects.prosa.it/gtkperl/
(has link to tutorial)
use Image::Magick: (generates file)
http://www.imagemagick.org/
http://www.imagemagick.org/www/perl.html
use GD; (generates file)
from: http://www.boutell.com/gd/
use SDL; (real-time apps/games)
example code & screen shots:
http://www.metaverse.fsnet.co.uk/sdlpl/screenshots/screenshots.html
http://sourceforge.net/projects/sdlpl/
------------------------------
Date: Sat, 7 Apr 2001 20:49:36 +0200
From: "alwin" <alwin@worldmail.nl>
Subject: can somebody explain
Message-Id: <9annic$54$1@nereid.worldonline.nl>
can somebody explain to me in englisch wat this means?
if ($test =~ /\S{2,}/)
Thanks a lot alwin
------------------------------
Date: Sat, 07 Apr 2001 19:07:09 GMT
From: sjs@linux.ca (Steven Smolinski)
Subject: Re: can somebody explain
Message-Id: <slrn9cuug0.oo.sjs@ragnar.stevens.gulch>
alwin <alwin@worldmail.nl> wrote:
> can somebody explain to me in englisch wat this means?
>
> if ($test =~ /\S{2,}/)
The =~ is the matching operator. See the perlop manpage. It returns
true in scalar context if the variable $test matches the regular
expression on the right hand side.
The regular expression itself is a short pattern. See the perlre
manpage for details. This one matches two or more ({2,})
non-whitespace characters (\S). See the docs, but IIRC a whitespace
character can be a space, tab, or newline.
--
Steven Smolinski => http://www.steven.cx/
------------------------------
Date: Sat, 07 Apr 2001 20:53:29 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: can somebody explain
Message-Id: <x7pueoqvna.fsf@home.sysarch.com>
>>>>> "SS" == Steven Smolinski <sjs@linux.ca> writes:
SS> alwin <alwin@worldmail.nl> wrote:
>> can somebody explain to me in englisch wat this means?
>>
>> if ($test =~ /\S{2,}/)
SS> The =~ is the matching operator. See the perlop manpage. It
SS> returns true in scalar context if the variable $test matches the
SS> regular expression on the right hand side.
better called the binding operator. that is what camel 3 uses. it binds
the expression on the left to the m///, s/// or tr/// on the right. by
default they all use $_ when nothing is bound. only one of the legal
operations on the right is match.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: Sat, 7 Apr 2001 15:54:58 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: complaint about moderation of this group
Message-Id: <Pine.A41.4.21.0104071552590.10784-100000@ginger.libs.uga.edu>
On Sat, 7 Apr 2001, Tad McClellan wrote:
> Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote:
> >Hah! I'd like to see you write a Perl program to cut down a Redwood with
> >a bana...Whoops, wrong thread.
>
>
> 1 while 1; # wait for the tree to rot and fall over
Good thing that's in Perl, because it'll have to be ported to a lot of new
OS's in the mean time. Version 49 perhaps?
Brad
------------------------------
Date: Sat, 07 Apr 2001 20:15:36 GMT
From: bogus@erol.com (---Pete---)
Subject: Re: complaint about moderation of this group
Message-Id: <3acf6ab4.388066356@news.earthlink.net>
On Sat, 07 Apr 2001 01:17:18 -0500, Kyle Dusang <hhsoft@csoft.net>
wrote:
>....I was also
>under the impression that Perl was a programming language that was
>used to create web applications. Sorry if this isn't as eloquently
>stated as I'd like it to be....but every time I ask a question in this
>group, one which concerns a PERL script I am working on...some anal
>retentive moderator tells me its off topic and that it doesn't deal
>specifically with PERL...
-------
This reply is to Kyle (if he actually exists) and to anyone else
new to Perl and interested in CGI.
I'm also new (about a month) to Perl and was a bit confused
at first as to why this group is NOT intended for Perl/CGI.
Reason being that everything I read about CGI said that CGI
is not a language; it's an interface -- and this is where the
confusion begins. For the newbe, it seems natural to think
that Perl will contain the commands and functions to perform
CGI related tasks, Right? WRONG! Keep reading.
However, once I got into CGI I discovered that there were
keywords related to the CGI that you must issue using Perl.
Keywords such as... "Location:", "Header" and so on.
These keywords or codes are NOT typically found in the
Perl docs because they are CGI codes a similar way that..
<font></font> is not a Perl command but rather an HTML
code that can be issued from Perl.
Once this simple concept clicked-in (my brain) I understood
why there exists a separate group for CGI issues.
With all that said, I invite Kyle or anyone else interested in
Perl/CGI or just CGI issues to post in newsgroup...
comp.infosystems.www.authoring.cgi
I suspect that people like Kyle perform an initial NG search
on "Perl" and no CGI groups come up. Therefore this group
with the "perl.misc" seems most appropriate for posting
Perl/CGI questions.
Suggestion:
If this "CGI off-topic" issue is an ongoing problem here, I
suggest that a new NG be fomed called... comp.lang.perl.cgi
or else simply direct the offending poster to...
comp.infosystems.www.authoring.cgi
PS: To anyone else like Kyle, it's not likely
that a new CGI newsgroup will be formed because
comp.infosystems.www.authoring.cgi
is low traffic as it is. I assume that CGI is off-topic here
in comp.lang.perl.misc bacause of the high amount of
traffic already, just dealing with plain old Perl topics.
---pete---
------------------------------
Date: Sat, 7 Apr 2001 16:03:07 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: cookie woes.
Message-Id: <Pine.A41.4.21.0104071555450.10784-100000@ginger.libs.uga.edu>
On Sat, 7 Apr 2001, J=FCrgen Exner wrote:
> You are asking "I can't get my groceries with my car" in a automobile
> newsgroup but actually you are expecting advice on how to build a road
> between your house and the grocery store. That's not gone work, dude ;-)
#!/usr/local/bin/perl
use warnings;
use strict;
print <<_end_;
I just installed a new battery (hopefully correctly) after paying two
different mechanics to do the same thing, and after paying for two towing
charges.
Could someone tell me how to find a competent mechanic?
_end_
TIA
Brad
------------------------------
Date: Sat, 7 Apr 2001 22:46:08 +0200
From: "novastar" <root@novastar.dtdns.net>
Subject: Re: Copy a directory structure
Message-Id: <9anqq6$mgf$1@usenet.otenet.gr>
Sorry there was a small mistake at the script . Now it is fixed and working 100%.
# This script will copy the whole source directory tree
# to the destination. Be carefull that if the root target
# ( destination ) directory does not exists then it will be
# created. This script will work only on Windows platforms,
# but with some small changes will work on unix as well.
# The destination files will be over writen if they exist.
# George Bouras
# root@novastar.dtdns.net
my $source_directory = 'f:/temp' ;
my $target_directory = 'c:/temp' ;
&xcopy($source_directory,$target_directory);
############# xcopy subroutine #############
sub xcopy
{
my ($pwd,$i)=($_[0],$i++);
die "You have not defined the \$target_directory variable, sorry...\n" if $target_directory eq "";
die "You have not defined the \$source_directory variable, sorry...\n" if -d $source_directory !=1;
if (( -d $target_directory !=1 ) && ( -e $target_directory ==1 ))
{
die "Can't continue because a file has target's dir name\n"
}
elsif ( -e $target_directory !=1 )
{
mkdir $target_directory || die "Couldn't create dir : $target_node\n"
}
opendir ($i,$pwd) || die "Can't list $pwd\n";
while (my $source_node=readdir $i)
{
next if $source_node=~/^\.*$/;
$source_node = $pwd.'/'.$source_node;
( my $relative_node ) = $source_node =~/$source_directory(.*)/;
$target_node = $target_directory.$relative_node;
if (-d $source_node==1)
{
if (( -d $target_node !=1 ) && ( -e $target_node ==1 ))
{
die "Can't mkdir $target_node because a same name file exist\n"
}
elsif (( -d $target_node ==1 ) && ( -e $target_node ==1 ))
{
print "inplace: $target_node already exist\n"
}
elsif ( -e $target_node !=1 )
{
print "mkdir : $target_node\n";
mkdir $target_node || die "Couldn't create dir : $target_node\n"
}
}
else
{
if (( -d $target_node ==1 ) && ( -e $target_node ==1 ))
{
warn "Can't copy $target_node because a same name dir exist\n"
}
else
{
print "coping : $source_node to $target_node\n" if -e $target_node !=1 ;
(my $copy_target_node) = $target_node; $copy_target_node=~s/\//\\/g ;
(my $copy_source_node) = $source_node; $copy_source_node=~s/\//\\/g ;
`$ENV{ComSpec} /c copy /b $copy_source_node $copy_target_node`;
}
}
&xcopy($source_node) if -d $source_node==1}
closedir $i}
------------------------------
Date: Sat, 7 Apr 2001 14:39:33 -0400
From: "Phil R Lawrence" <prlawrence@lehigh.edu>
Subject: Re: inheritance within one file?
Message-Id: <9anmt4$c8o@fidoii.CC.Lehigh.EDU>
[cc: Uri Guttman <uri@sysarch.com>]
"Uri Guttman" <uri@sysarch.com> wrote:
> >>>>> "LS" == Logan Shaw <logan@cs.utexas.edu> writes:
>
> LS> In article <9am3hi$k14@fidoii.CC.Lehigh.EDU>,
> LS> Phil R Lawrence <prlawrence@lehigh.edu> wrote:
> >> package A;
> >> sub foo {
> >> my $proto = shift;
> >> my $class = ref($proto) || $proto;
> >> my $self = {};
> >> bless ($self,$class);
> >> return $self;
> >> }
> >>
> >> package B;
> >> # Obviously the wrong mechanism ->
> >> use vars qw( @ISA );
> >> @ISA = qw ( A );
> >> use A;
>
> >> sub new {
> >> # I want to inherit A's foo method!
> >> my $b = $self->foo;
> >> }
> >>
> >> package main;
> >> my $b = B->new;
> >> ----------------------------
>
> LS> This doesn't work because "use" is like "require" followed by
> LS> "import", and "require" reads from a file on disk.
>
> but he is using object calls, not imported subs. so that has no
bearing
> on his problem. the use call is useless here as it doesn't load any
code
> and probably will bomb as A.pm won't be found.
>
> from a quick glance at it, it should work fine if the use call is
> deleted. he sets up the @ISA before the B->new() call is made.
Quite so. Thanks for the clarification. Also, Camel v.3 put me on to
use base, so here is a nice test script:
---------------------------------
#!../../perl
package A;
sub foo {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
bless ($self,$class);
return $self;
}
package B;
use base A;
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $b = $class->foo;
}
package C;
use base B;
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $c = $class->foo;
}
package main;
print 'a: ', A->foo, "\n";
print 'b: ', B->new, "\n";
print 'c: ', C->new, "\n";
__END__
results in:
a: A=HASH(0x20019bcc)
b: B=HASH(0x20029250)
c: C=HASH(0x20029298)
---------------------------------
------------------------------
Date: 7 Apr 2001 15:05:19 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: inheritance within one file?
Message-Id: <9anrtv$3vf$1@ahab.cs.utexas.edu>
In article <x7ae5ts4na.fsf@home.sysarch.com>,
Uri Guttman <uri@sysarch.com> wrote:
[ I, Logan Shaw <logan@cs.utexas.edu>, mentioned "import" ]
>but he is using object calls, not imported subs. so that has no bearing
>on his problem. the use call is useless here as it doesn't load any code
>and probably will bomb as A.pm won't be found.
By mentioning "import" in the first place, I was just trying to give a
nice general answer that would explain how to "use" in-file modules
in general.
I like to give answers which are more general than required for the
specific question asked because (a) it's fun, (b) others will read the
post, and (c) people often formulate their questions wrong.
By the way, import is method call. You could just as well say that
use Foo qw{ foo bar };
is equivalent to
BEGIN
{
require Foo;
Foo->import qw{ foo bar };
}
instead of saying it's equivalent to
BEGIN
{
require Foo;
import Foo qw{ foo bar };
}
I have to confess I don't know why import is defined by default, but it
is. In other words, I have tried
#! /usr/local/bin/perl
package A;
sub foo { print "A::foo\n"; }
# -----
package main;
A->import;
A::foo;
and it works, but I would have expected to need to do this:
#! /usr/local/bin/perl
package A;
require Exporter;
@ISA = qw{ Exporter };
# -----
package main;
A->import;
A::foo;
For some reason, A seems to magically inherit import without my having
to do anything. Maybe this is just yet another DWIM thing.
- Logan
--
whose? my your his her our their _its_
who's? I'm you're he's she's we're they're _it's_
------------------------------
Date: Sat, 07 Apr 2001 20:36:25 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: inheritance within one file?
Message-Id: <x7zodsqwfp.fsf@home.sysarch.com>
>>>>> "PRL" == Phil R Lawrence <prlawrence@lehigh.edu> writes:
PRL> package B;
PRL> use base A;
that is a bareword. 'A' should be quoted. arguments on a use line are
not special like the class/pragma name is.
PRL> package C;
PRL> use base B;
ditto
PRL> my $c = $class->foo;
even though your code is legal, i prefer the $obj->meth() style for
visual reasons.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: Sat, 07 Apr 2001 20:45:11 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: inheritance within one file?
Message-Id: <x7wv8wqw14.fsf@home.sysarch.com>
>>>>> "LS" == Logan Shaw <logan@cs.utexas.edu> writes:
LS> In article <x7ae5ts4na.fsf@home.sysarch.com>,
LS> Uri Guttman <uri@sysarch.com> wrote:
LS> [ I, Logan Shaw <logan@cs.utexas.edu>, mentioned "import" ]
>> but he is using object calls, not imported subs. so that has no bearing
>> on his problem. the use call is useless here as it doesn't load any code
>> and probably will bomb as A.pm won't be found.
LS> By mentioning "import" in the first place, I was just trying to give a
LS> nice general answer that would explain how to "use" in-file modules
LS> in general.
i realized you mentioned import. but he was doing object stuff and
import and OO perl are not related.
LS> I like to give answers which are more general than required for the
LS> specific question asked because (a) it's fun, (b) others will read the
LS> post, and (c) people often formulate their questions wrong.
a) maybe.
b) possibly
c) not in this case. he showed real code and asked why his object method
call was not being inherited.
LS> I have to confess I don't know why import is defined by default, but it
LS> is. In other words, I have tried
import is defined by UNIVERSAL which is inherited by all classes.
LS> package A;
LS> sub foo { print "A::foo\n"; }
LS> # -----
LS> package main;
LS> A->import;
that is a no-op. you import nothing into class main. the default import
in UNIVERSAL uses the @EXPORT and @EXPORT_OK package variables and you
don't declare or assign to them.
LS> A::foo;
LS> and it works, but I would have expected to need to do this:
LS> #! /usr/local/bin/perl
LS> package A;
LS> require Exporter;
LS> @ISA = qw{ Exporter };
LS> # -----
LS> package main;
LS> A->import;
LS> A::foo;
LS> For some reason, A seems to magically inherit import without my having
LS> to do anything. Maybe this is just yet another DWIM thing.
like i said above, importing and object calls have nothing to do with
each other. importing aliases perl symbols from one package space to
another. that is all it does. it does not enable anything to do with
object methods. you can call any sub by its fully qualified name (as you
do with A::foo) and not need to import. similarly you can call any
method via an object or a class name without using import. A->foo would
call A::foo and pass 'A' as the only argument to the method.
read object oriented perl or take damian's class in boston (see below)
to really learn about OO perl.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: 7 Apr 2001 10:18:40 -0700
From: Patrick Flaherty <Patrick_member@newsguy.com>
Subject: looking up Windows ODBC DSNs across the network
Message-Id: <9ani5g020dk@drn.newsguy.com>
Hello,
What would I need to add and how then do I modify the following to look up DSNs
on a remote W2000 mch (from a local W2000 mch)?
use DBI;
use DBI qw(:sql_types);
use strict;
# This will give you a list of available drivers installed.
my @drivers = DBI->available_drivers;
thanx.
pat
------------------------------
Date: Sat, 7 Apr 2001 20:39:10 +0200
From: "Bert" <webmaster@netdating.nl>
Subject: Re: problem with making dirs!
Message-Id: <3acf5e3e$0$13309@reader5>
> Because it is not Mr. Perl's problem.
>
> It is Mr. Web Server's problem.
aha... well thank you a lot for the advice.
Exially it's not my own server, it's a hosting compagny (www.is.nl) where
i'm a member. Isn't it unproffesional of them? well... i guess it is.. :)
I've contacted them already so they will have to do something about it..
Thanks again for your time!
Bert
------------------------------
Date: Sat, 07 Apr 2001 20:26:31 +0200
From: Christoph Bergmann <info@java.seite.net>
Subject: Re: problem with quoting or how to avoid \n at the the end of <<EOF?
Message-Id: <3ACF5BD7.6CA8@java.seite.net>
Jeff Pinyan wrote:
>
> On Apr 6, Christoph Bergmann said:
>
> >but i have the problem, that i want to give the above code to another
> >subroutine which eval's the code later (there are reasons why)...
> >
> >&anothersub('&somesub($val)');
>
> Don't use eval(), then. Use a code reference.
>
> anothersub( sub { somesub($val) } );
>
> Then:
>
> sub anothersub {
> my $cref = shift;
> # ...
> $cref->(); # executes the function
> }
>
unfortunately, in the "real-life" program, where i have this problem,
this isn't possible because the eval'ed code comes from "outside". it is
a little bit something like a "stored procedure"... i think eval is
necessary at this point.
or, in other words:
is there a possibility to write
$x=<<EOF
text
EOF
without an additional \n at the end of "text" ??
best regards,
christoph bergmann
------------------------------
Date: Sat, 07 Apr 2001 20:35:14 +0200
From: Mona Wuerz <wuerz@yahoo.com>
Subject: Re: problem with quoting or how to avoid \n at the the end of <<EOF?
Message-Id: <070420012035148580%wuerz@yahoo.com>
In article <3ACF5BD7.6CA8@java.seite.net>, Christoph Bergmann
<info@java.seite.net> wrote:
> is there a possibility to write
>
> $x=<<EOF
> text
> EOF
>
> without an additional \n at the end of "text" ??
not that I know of, but what's wrong with chomp, if the \n bothers you?
-mona
------------------------------
Date: Sat, 7 Apr 2001 15:26:38 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: problem with quoting or how to avoid \n at the the end of <<EOF?
Message-Id: <slrn9cuqfe.ou9.tadmc@tadmc26.august.net>
Christoph Bergmann <info@java.seite.net> wrote:
>is there a possibility to write
>
>$x=<<EOF
>text
>EOF
No, because that has a syntax error :-)
>without an additional \n at the end of "text" ??
$x="text";
Here-docs are merely another form of quoting.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 7 Apr 2001 15:24:02 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: problem with quoting or how to avoid \n at the the end of <<EOF?
Message-Id: <9ant12$46e$1@ahab.cs.utexas.edu>
In article <slrn9cuqfe.ou9.tadmc@tadmc26.august.net>,
Tad McClellan <tadmc@augustmail.com> wrote:
>Christoph Bergmann <info@java.seite.net> wrote:
>
>>is there a possibility to write
>>
>>$x=<<EOF
>>text
>>EOF
>
>
>No, because that has a syntax error :-)
It does?
$ perl -d heredoc
[ snip ]
Enter h or `h h' for help.
main::(heredoc:1): $x=<<EOF
main::(heredoc:2): text
main::(heredoc:3): EOF
DB<1> n
Debugged program terminated.
[ snip ]
DB<1> x $x
0 'text
'
DB<2>
Looks O.K. to me.
- Logan
--
whose? my your his her our their _its_
who's? I'm you're he's she's we're they're _it's_
------------------------------
Date: Sat, 07 Apr 2001 20:51:10 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: problem with quoting or how to avoid \n at the the end of <<EOF?
Message-Id: <x7snjkqvr4.fsf@home.sysarch.com>
>>>>> "LS" == Logan Shaw <logan@cs.utexas.edu> writes:
LS> In article <slrn9cuqfe.ou9.tadmc@tadmc26.august.net>,
LS> Tad McClellan <tadmc@augustmail.com> wrote:
>> Christoph Bergmann <info@java.seite.net> wrote:
>>
>>> is there a possibility to write
>>>
>>> $x=<<EOF
>>> text
>>> EOF
>>
>>
>> No, because that has a syntax error :-)
try that without the trailing newline in the data. that is tad's
point. here docs SYNTAX requires the data string to always have a
trailing newline as the end token has to begin a line. this is one of
those areas (pod is another) where whitespace matters in perl.
and it is so easy to chomp/chop off the trailing newline that it is not
worth answering. and trying to use multiline quoted strings with quote
chars or q/qq is annoying. you have to continue the statement on the
other side of the string which is not visually clear.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: Sun, 8 Apr 2001 04:15:11 +1000
From: "hangover" <matt@webexplorers.com.au>
Subject: Re: Radius detail File to csv
Message-Id: <3acf5a4c$1_4@news01.one.net.au>
Hmmm your right ... probably the answer i deserved,
Teach an man to fish ......
i'll be back with more questions! :)
-Matt
Rick Delaney <rick.delaney@home.com> wrote in message
news:3ACF34AE.48C031A4@home.com...
> [posted & mailed]
>
> hangover wrote:
> >
> [snip]
> > If someone has such a beast or is feeling generous enough to whip one
up, i
> > would be most appreciative!
>
> If you're just looking to find scripts, a search engine will probably be
> more fruitful than this newsgroup.
>
> > I am not able to do something like this myself at this stage :(
>
> If you're willing to try then feel free to ask questions when you get
> stuck (but check the FAQ first). If not, then I suggest you hire a
> programmer.
>
> --
> Rick Delaney
> rick.delaney@home.com
------------------------------
Date: Sat, 7 Apr 2001 17:13:41 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Radius detail File to csv
Message-Id: <Pine.A41.4.21.0104071644470.10784-100000@ginger.libs.uga.edu>
On Sun, 8 Apr 2001, hangover wrote:
> Hmmm your right ... probably the answer i deserved,
>
> Teach an man to fish ......
>
> i'll be back with more questions! :)
Your attitude is refreshing. I did the code below as a lark.
I don't know if there are more fields than those you showed, and
I'm doing simple quoting: "text","","number","\"text in quotes\"".
Perhaps you'll find it useful, or at least interesting.
Brad
#!/usr/local/bin/perl
use warnings;
use strict;
my %h = (
'Acct-Authentic' => '',
'Acct-Delay-Time' => '',
'Acct-Input-Octets' => '',
'Acct-Input-Packets' => '',
'Acct-Multi-Session-Id' => '',
'Acct-Output-Octets' => '',
'Acct-Output-Packets' => '',
'Acct-Session-Id' => '',
'Acct-Session-Time' => '',
'Acct-Status-Type' => '',
'Acct-Terminate-Cause' => '',
'Ascend-Data-Rate' => '',
'Ascend-Xmit-Rate' => '',
'Called-Station-Id' => '',
'Calling-Station-Id' => '',
'Framed-IP-Address' => '',
'Framed-Protocol' => '',
'NAS-Identifier' => '',
'NAS-Port-Id' => '',
'NAS-Port-Type' => '',
'Request-Authenticator' => '',
'Service-Type' => '',
'Timestamp' => '',
'User-Name' => '',
);
{
local $/ = ''; ### paragraph mode
while( <> ) {
my %newh = %h;
foreach ( split "\n" ) {
if( /\s*(\S+)\s*=\s*(.*)/ ) {
my ( $name, $value ) = ( $1, $2 );
$value =~ s/"/\\"/g;
$newh{ $name } = $value;
} # if
} # foreach
print '"', join( '","', map {$newh{$_}} sort keys %newh ), "\"\n";
} # while
}
------------------------------
Date: Sat, 07 Apr 2001 21:53:28 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Radius detail File to csv
Message-Id: <x7k84wqsvc.fsf@home.sysarch.com>
>>>>> "BB" == Brad Baxter <bmb@ginger.libs.uga.edu> writes:
some minor and style improvements
BB> my %h = map { $_, '' } qw(
Acct-Authentic
Acct-Delay-Time
Acct-Input-Octets
Acct-Input-Packets
Acct-Multi-Session-Id
Acct-Output-Octets
Acct-Output-Packets
Acct-Session-Id
Acct-Session-Time
Acct-Status-Type
Acct-Terminate-Cause
Ascend-Data-Rate
Ascend-Xmit-Rate
Called-Station-Id
Calling-Station-Id
Framed-IP-Address
Framed-Protocol
NAS-Identifier
NAS-Port-Id
NAS-Port-Type
Request-Authenticator
Service-Type
Timestamp
User-Name
);
isn't that easier to read and maintain?
BB> {
BB> local $/ = ''; ### paragraph mode
BB> while( <> ) {
BB> my %newh = %h;
why copy the whole hash over? you can just clear its values
@h{ keys %h } = () ;
or
@h{ keys %h } = ('') x keys %h ;
to set them all to null strings
BB> foreach ( split "\n" ) {
BB> if( /\s*(\S+)\s*=\s*(.*)/ ) {
BB> my ( $name, $value ) = ( $1, $2 );
do the assignment in the if clause
if( my ( $name, $value ) = /\s*(\S+)\s*=\s*(.+)/ ) {
i changed the .* to .+ .
you could convert the foreach/split as well
while( my ( $name, $value ) = /^\s*(\S+)\s*=\s*(.+)/gm ) {
this assumes each key=value pair starts on it own line which seems to be
what you were doing.
BB> $value =~ s/"/\\"/g;
BB> $newh{ $name } = $value;
BB> } # if
BB> } # foreach
with deeper nesting, you wouldn't need to comment close braces. 2 char
indents are cheap. use 4 or 8. those comments are noisy
BB> print '"', join( '","', map {$newh{$_}} sort keys %newh ), "\"\n";
hmm, there are MANY ways to print a sorted hash. that is one of the
uglier ones. also there is no need for the map as a hash slice will do
fine. does the value have to have "" around it?
how about this one:
{ local $" = q{","} ;
print qq{"@newh{sort keys %newh}"\n} ;
}
i think that is a lot clearer.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: Sat, 07 Apr 2001 19:15:38 GMT
From: "Wes" <theXYZtenor@attXYZ.XYZnet>
Subject: sendmail script - got to be something simple
Message-Id: <uHJz6.53601$hf.23315624@news1.elmhst1.il.home.com>
I appologize for posting this here, but I'm not sure if I've got a perl,
sendmail or server problem. This has got to be something so obvious: I'm
trying to run a simple sendmail script on an AT&T small business hosting
server and I have yet to be able to send mail. So far the folks at AT&T
haven't been very helpful.
script follows:
if ( !open(MAIL, "|/usr/lib/sendmail -t") ) {
print "Open mail failed\n";
exit;
}
print MAIL "To: me\@noplace.com\n";
print MAIL "From: me\@somewhere.net\n";
print MAIL "Subject: Testing mail script\n\n";
print MAIL "This is a test\n\n";
close (MAIL);
...remaining script generates html
The subsequent html in my script gets generated indicating the script
finishes. If I run with -d option I get the following output.
main::(/usr/local/apache/htdocs/hosts/meetinga/cgi-local/TestMail.pl:36):
36: if ( !open(MAIL, "|/usr/lib/sendmail -t") ) {
DB<1> Can't modify constant item in scalar assignment at (eval 3) line 2,
at EOF
DB<2>
------------------------------
Date: Sat, 07 Apr 2001 20:19:24 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: speed of strings and arrays?
Message-Id: <gDKz6.91803$Ok4.7282263@news1.rdc1.ct.home.com>
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> According to Dan Sugalski <dan@tuatha.sidhe.org>:
>> Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> [array implementation in Perl]
>> > No, it's for real. A Perl array is an actual array (of pointers to the
>> > scalar values). The push and pop operators work on the upper end of
>> > the array and take unit time (unless push requires re-allocation).
>> > shift and unshift operate at the beginning and the rest of the array
>> > is copied every time. Again, arrays are rarely so big that it matters.
>>
>> This isn't entirely true. Perl keeps a pointer to the 'real' beginning of
>> the array under the hood. If you shift and then unshift, perl doesn't copy
>> anything because it doesn't need to. It's only when you unshift things
>> such that there is no 'extra' space on the beginning that perl has to move
>> things.
> Ah, thanks. So in general a Perl array lives somewhere in the middle
> of an allocated bit of storage and is moved only when it hits the ends.
> Good to know.
Pretty much. Perl doesn't really allocate spare space at the beginning of
an array, so this:
@foo = (1,2,3);
unshift @foo, 1;
will end up doing a copy. Perl does end up allocating extra space off the
end of an array when you extend it under most circumstances. Currently the
new array size (under the hood--your perl code doesn't see this) will be
as big as needed for the extend plus 20% of the pre-extended array
size. That means that this:
my @foo;
$foo[99] = 1;
$foo[100] = 1;
will end up with perl allocating space for 120 entries total in the foo
array. (Not that knowing this is really needed, but...)
Dan
------------------------------
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 650
**************************************