[7536] in Perl-Users-Digest
Perl-Users Digest, Issue: 1163 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 12 17:17:12 1997
Date: Sun, 12 Oct 97 14:00:28 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 12 Oct 1997 Volume: 8 Number: 1163
Today's topics:
Re: #!/usr/bin/perl for NT ??? (Steven Sajous)
?Help making MakeMaker/NT keng@removethis.wco.com
Breaking out of a foreach loop franklin@nospamingideas4you.com
Re: Breaking out of a foreach loop (brian d foy)
Re: Breaking out of a foreach loop (Tad McClellan)
Re: Breaking out of a foreach loop <merlyn@stonehenge.com>
exp1 ? exp2 : exp 3 -- whats wrong? <Janning.Vygen@bonn.netsurf.de>
Re: exp1 ? exp2 : exp 3 -- whats wrong? (Tad McClellan)
Re: exp1 ? exp2 : exp 3 -- whats wrong? (Tushar Samant)
Re: exp1 ? exp2 : exp 3 -- whats wrong? <bholzman@mail.earthlink.net>
Re: file handle names (dave)
Re: Getting File Information Quickly franklin@nospamingideas4you.com
help building libraries keng@removethis.wco.com
How can I use perl to communicate with rstatd? <efinch@vais.net>
Re: inheriting filehandles from Win32::Process::Create <reiter@research.att.com>
Multidimensional Arrays <ryanr@poolpros.com>
Re: Perl vs. Java geldridg@progsoc.uts.edu.au
Problem with unix command nguyent@uvil204.fr.ec.ps.net
Q: Dynamically creating hashes and arrays (Hans Malmberg)
Re: Replacing anything not matching with s/? (Eric Bohlman)
Re: Replacing anything not matching with s/? (Toutatis)
Re: Replacing anything not matching with s/? <dankogai@dan.co.jp>
Re: SOLUTION: Are there problems using back quotes on W (Eric Bohlman)
Telnet <support@huron.net>
Re: Telnet (Shawn Wagner)
Re: Telnet (I R A Aggie)
Re: Time? (Clay Irving)
Re: truncate() & FileHandle(s) (Eric Bohlman)
Re: truncate() & FileHandle(s) (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 12 Oct 1997 11:01:52 GMT
From: stevee@moon.jic.com (Steven Sajous)
Subject: Re: #!/usr/bin/perl for NT ???
Message-Id: <3440adc2.148881039@news2.jic.com>
You have to associate your .pl files with Perl for them to be executed
in UNIX
I am pretty sure there is an FAQ on the www.activeware.com site which
deals witht this
On 8 Oct 1997 19:39:49 GMT, "Authorized User"
<matthew.kravitz@systecinc.com> wrote:
>i know how to declare a perl script in unix, but how is this accomplished
>in NT?
>i wanted to avoid typing 'perl <script_name> .
>
>thanks,
>matthew e. kravitz
>
------------------------------
Date: 12 Oct 1997 12:12:35 GMT
From: keng@removethis.wco.com
Subject: ?Help making MakeMaker/NT
Message-Id: <61qerj$m2a$1@news.wco.com>
Running Perl/Win32 on WindowsNT, and trying to build LWP, I ran into the
problem that I seem to not have MakeMaker. So I got the sources for
MakeMaker, and when trying to build them, I seemed to be missing extutils.
Fine, get the extutils, and try to build that, but of course I can't,
because I don't have MakeMaker!?!?!
Isn't MakeMaker and/or extutils supposed to be part of the perl5
distribution? Did I forget something? I installed Pw32i310, plsei310,
and Piis310. Can someone help me sort this out?
Thanks,
keng@remove_this.wco.com
------------------------------
Date: Sun, 12 Oct 97 03:23:33 -0400
From: franklin@nospamingideas4you.com
Subject: Breaking out of a foreach loop
Message-Id: <34407ba2$3$senaxyva$mr2ice@news.alltel.net>
How do you break out of foreach loop.
Example:
foreach ??? (???) {
if () {
if () {
suchandsuch;
breakfromloop;
}
}
}
--
-----------------------------------------------------------
Coming Soon,
"Discussion Groups" the power of the news groups packed into the manageablity of a mail list.
Virtual Computer Shopper
VCS Manager: Franklin Smith
E-Mail Address: franklin@ideas4you.com
Web Site: http://www.ideas4you.com/vcs
Ideas Unlimited Consulting
http://www.ideas4you.com
We do custom REXX and Paradox programming, Web Site Construction and Management, and Computer Hardware and Software Sales and Service.
Books Unlimited
BU Mangaer: Jim Smith
E-Mail Address: jimsmith@ideas4you.com
http://www.ideas4you.com/bu
-----------------------------------------------------------
------------------------------
Date: Sun, 12 Oct 1997 09:33:38 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Breaking out of a foreach loop
Message-Id: <comdog-1210970933380001@netnews.worldnet.att.net>
In article <34407ba2$3$senaxyva$mr2ice@news.alltel.net>,
franklin@nospamingideas4you.com wrote:
> How do you break out of foreach loop.
see the keywords next and last.
for example:
foreach $element (@array)
{
next if $element ne 'Chlorine';
last if $element eq 'Argon';
#your code here
}
--
brian d foy <http://computerdog.com>
#!/usr/bin/perl
$_=q|osyrNewkecnaYhe.mlorsePptMskurj|;s;[NY.PM]; ;g;local$\=
qq$\n$;@pm=split//;while($NY=pop @pm){$pm.=$NY;$ny.=pop @pm}
$pm=join'',reverse($ny,$pm);open(NY,'>&STDOUT');print NY $pm
------------------------------
Date: Sun, 12 Oct 1997 10:14:19 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Breaking out of a foreach loop
Message-Id: <bgpq16.721.ln@localhost>
franklin@nospamingideas4you.com wrote:
: How do you break out of foreach loop.
last;
[
18 line sig on a 12 line article?
Sheesh. Sheesh.
You are using 2-3 times the bandwidth necesary. Please don't do
that. That is an abuse of the Internet. Use what you need, don't
use more than you need.
Internet abusers eventually end up in everybody's killfile, and then
never get their questions answered...
]
--
Tad McClellan SGML Consulting
tadmc@flash.net Perl programming
Fort Worth, Texas
------------------------------
Date: 12 Oct 1997 09:20:54 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: franklin@ideas4you.com
Subject: Re: Breaking out of a foreach loop
Message-Id: <8csou7j6l5.fsf@gadget.cscaper.com>
>>>>> "franklin" == franklin <franklin@nospamingideas4you.com> writes:
franklin> How do you break out of foreach loop.
franklin> Example:
franklin> foreach ??? (???) {
franklin> if () {
franklin> if () {
franklin> suchandsuch;
franklin> breakfromloop;
franklin> }
franklin> }
franklin> }
Replace "breakfromloop" with "last".
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 323 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Sun, 12 Oct 1997 15:08:59 +0100
From: Janning Vygen <Janning.Vygen@bonn.netsurf.de>
Subject: exp1 ? exp2 : exp 3 -- whats wrong?
Message-Id: <3440D9FB.C42EA37D@bonn.netsurf.de>
following perlscript doesnt work correctly to me:
-------------------------------
#!usr/bin/perl
print "content-type: text/plain\n\n";
$flag=1;
# first condition
if ($flag==1) {$color="blue";} else
{$color="red";} # output should be "1: blue"
print "1: $color \n";
# second condition
$flag==1 ? $color="blue" :
$color="red"; # output
should be "2:blue" but it is "2: red" !!!!!!!
print "2: $color \n";
# third condition
$flag==1 ? print "3: blue \n" : print "3: red
\n"; # output should be "3: blue"
-----------------------------------------------------
the second condition is true, but the output is
"2: red".
Did I forget any brackets?? But why does the third
condition work correctly?
Im working with "perl, version 5.003_07 [...] Perl
for Win32 Build 306 - Built 17:50:28 Apr 10 1997 "
(perl.exe -v)
Did I make any mistake??Am i stupid?? Please tell
me, 'cause i dont know yet. :-)
Janning
Bonn - Germany
------------------------------
Date: Sun, 12 Oct 1997 10:05:14 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: exp1 ? exp2 : exp 3 -- whats wrong?
Message-Id: <avoq16.f01.ln@localhost>
Janning Vygen (Janning.Vygen@bonn.netsurf.de) wrote:
: following perlscript doesnt work correctly to me:
: # second condition
: $flag==1 ? $color="blue" :
: $color="red"; # output
: should be "2:blue" but it is "2: red" !!!!!!!
: print "2: $color \n";
$color = $flag==1 ? 'blue' : 'red';
print "2: $color \n";
--
Tad McClellan SGML Consulting
tadmc@flash.net Perl programming
Fort Worth, Texas
------------------------------
Date: 12 Oct 1997 13:13:33 -0500
From: scribble@shoga.wwa.com (Tushar Samant)
Subject: Re: exp1 ? exp2 : exp 3 -- whats wrong?
Message-Id: <61r40d$h5n@shoga.wwa.com>
janning.vygen@bonn.netsurf.de writes:
>
>$flag=1;
>
># second condition
>$flag==1 ? $color="blue" :
>$color="red";
>print "2: $color \n";
Then you might find this even more mysterious:
1 ? $a="a" : $b="b";
print "a = $a, b = $b \n";
Surprised? It parses as
(1? $a="a" : $b) = "b";
and the left hand side happens to be asignable, and assigning
to it assigns to $a.
There's no "explanation" for why this works this way and your
other expression works "right". The only answer is: that's how
they get parsed.
------------------------------
Date: Sun, 12 Oct 1997 15:47:53 -0400
From: Benjamin Holzman <bholzman@mail.earthlink.net>
To: Janning Vygen <Janning.Vygen@bonn.netsurf.de>
Subject: Re: exp1 ? exp2 : exp 3 -- whats wrong?
Message-Id: <34412969.DDA1A46A@mail.earthlink.net>
[posted & mailed]
Janning Vygen wrote:
>
> following perlscript doesnt work correctly to me:
> -------------------------------
> #!usr/bin/perl
> print "content-type: text/plain\n\n";
> $flag=1;
>
> # first condition
> if ($flag==1) {$color="blue";} else
> {$color="red";} # output should be "1: blue"
> print "1: $color \n";
>
> # second condition
> $flag==1 ? $color="blue" :
> $color="red"; # output
> should be "2:blue" but it is "2: red" !!!!!!!
> print "2: $color \n";
>
> # third condition
> $flag==1 ? print "3: blue \n" : print "3: red
> \n"; # output should be "3: blue"
> -----------------------------------------------------
>
> the second condition is true, but the output is
> "2: red".
> Did I forget any brackets?? But why does the third
> condition work correctly?
> Im working with "perl, version 5.003_07 [...] Perl
> for Win32 Build 306 - Built 17:50:28 Apr 10 1997 "
> (perl.exe -v)
>
> Did I make any mistake??Am i stupid?? Please tell
> me, 'cause i dont know yet. :-)
I didn't believe this until I tried it, but it looks like this is a bug,
at least in perl 5.003_07 for Win32 Build 306. Although the right-hand
side of a (?:) expression isn't supposed to be evaluated if the
condition is false, I'm guessing the optimizer is getting in the way
here, and simplifying an expression, unwittingly producing an unwanted
side-effect. The simple solution would be not to use side-effects in a
(?:) expression, which is pretty easy. Your code would read:
$color = ($flag ? 'blue' : 'red');
which is how the (?:) operator was intended to be used, anyway. The
reason I think it's the optimizer is that this code:
$flag ? ($color='blue') =~ m/./ : ($color='red') =~ m/./;
does work as intended ($color becomes 'blue'). I'm going to try this on
Solaris at work on Monday, 'cause I'm real curious if this behaviour
still exists in 5.004.
>
> Janning
> Bonn - Germany
------------------------------
Date: Sun, 12 Oct 1997 04:02:31 GMT
From: over@the.net (dave)
Subject: Re: file handle names
Message-Id: <34404b3c.3398209@news.one.net>
Alvin Tanhehco <alvin@qualcomm.com> wrote:
>How do I go about opening and closing file handles with sequential names
>like OUT1, OUT2, OUT3...? I tried OUT($num), {OUT}$num, but these don't
>work.
Take a look at the FileHandle module. It returns filehandles much like C
returns file descriptors so you don't worry about naming them yourself.
Dave
|
| Please visit me at http://w3.one.net/~dlripber
|
| For reply by email, use:
| dlripber@one.net
|________
------------------------------
Date: Sun, 12 Oct 97 11:14:54 -0400
From: franklin@nospamingideas4you.com
Subject: Re: Getting File Information Quickly
Message-Id: <3440ec0c$4$senaxyva$mr2ice@news.alltel.net>
In <344037D4.3C2A8935@ghg.net>, on 10/11/97
at 09, "David A. Barnett" <barnetda@ghg.net> said:
>franklin@nospamingideas4you.com wrote:
>> Is there a way to read a get all the directory information. Kind of like
>> doing a DOS Dir to get the filename, size, etc... with out having to set a
>> File Handle for each file and then doing a stat.
> Wouldn't:
> @DirectoryInformation = `ls -al /usr/bin`
>work? I think so. Should put all ls info into the
>@DirectoryInformation, where you can use foreach loop to go through each
>entry.
This can be done with opendir() and readdir(). What I need quick access
to is file size, if it's a directory or not, etc... I finally found the
stat() function but the problem is the only thing I can see in that
information that may tell me wether or not it's a directory is $nlink.
--
-----------------------------------------------------------
Coming Soon,
"Discussion Groups" the power of the news groups packed into the manageablity of a mail list.
Virtual Computer Shopper
VCS Manager: Franklin Smith
E-Mail Address: franklin@ideas4you.com
Web Site: http://www.ideas4you.com/vcs
Ideas Unlimited Consulting
http://www.ideas4you.com
We do custom REXX and Paradox programming, Web Site Construction and Management, and Computer Hardware and Software Sales and Service.
Books Unlimited
BU Mangaer: Jim Smith
E-Mail Address: jimsmith@ideas4you.com
http://www.ideas4you.com/bu
-----------------------------------------------------------
------------------------------
Date: 12 Oct 1997 15:30:14 GMT
From: keng@removethis.wco.com
Subject: help building libraries
Message-Id: <61qqe6$oqk$1@news.wco.com>
Trying to install libnet-1.0505 (and others) I get the message:
"Checking to see if your kit is complete....
Can't locate ExtUtils/Manifest.pm in @INC at (eval 1) line 374.
There is indeed no "manifest.pm" in the extutils directory. Was that
supposed to have been generated when I installed the Perl/Win32 source?
Thanks!
------------------------------
Date: Sun, 12 Oct 1997 01:24:46 -0400
From: Ed Finch <efinch@vais.net>
Subject: How can I use perl to communicate with rstatd?
Message-Id: <34405F1E.68562E0B@vais.net>
I would like to write a perl script to query/interact with the rstatd
daemon on a remote system. I've searched the man pages, etc. but am
unable to find any detailed information. How can this be done? Are there
existing scripts? Archives/man pages/etc. of the information I need?
Thanks!
Ed
------------------------------
Date: Sun, 12 Oct 1997 19:06:45 GMT
From: Mike Reiter <reiter@research.att.com>
Subject: Re: inheriting filehandles from Win32::Process::Create
Message-Id: <34411FC4.9A5F86A4@research.att.com>
Josh Baudhuin wrote:
> Uh, very likely the spawned perl task doesn't inherit the filehandles of the
> previous perl script. The Create() API (::CreateProcess()) is talking about
> handles in the Win32 sense of the word, not in the perl sense of the word...
>
> I'm not sure if you CAN refer to the handles the spawning process is giving
> to the spawned, unless you use lower-level I/O to which you'd pass the
> actual Win32 HANDLE.
>
> You SHOULD be able, at least, to give the child process your current
> standard in/out/err, if that helps.
I've tried "tricking" the child into inheriting the right filehandle (a
socket connection, in my case) by naming it STDOUT in the parent before
I spawn the child. This doesn't work, either.
Sigh. It looks like I need to understand Win32 handles, so I can try
your suggestion of passing it explicitly via low-level I/O. Can you
suggest a reference for them?
- Mike
------------------------------
Date: Sun, 12 Oct 1997 04:25:41 -0700
From: ryanr <ryanr@poolpros.com>
Subject: Multidimensional Arrays
Message-Id: <3440B3B5.972D9BC1@poolpros.com>
I have a tabel of data that has widths, and lengths.. and then
corresponding prices for all.
the table looks like this:
Widths 10 20 30 40 50 60 70
Lengths 10 12 13 14 15 16 17 18
20 19 20 21 22 23 24 25
30 26 27 28 29 30 31 32
40 33 34 35 36 37 38 39
50 40 41 42 43 44 45 46
60 47 48 49 50 51 52 53
70 54 55 56 57 58 59 60
I'm not really sure how I should go about storing this table. I would
like to just put it in a standard multidimensional array, but I'm not
sure I fully understand how to do it in perl.
Thanks... Ryan
------------------------------
Date: Sun, 12 Oct 1997 03:11:05 -0600
From: geldridg@progsoc.uts.edu.au
Subject: Re: Perl vs. Java
Message-Id: <876643454.16972@dejanews.com>
In article <34403FE5.D63BDBC@acc.mcrest.edu>,
polone@acc.mcrest.edu wrote:
> ... Perl can be an OOP
> language, supporting objects, polymorphism, inheritance, multiple
> inheritance, and overlays...
The ``OO Soapbox'' maybe of some use to those following this thread.
You can find it at:
http://www.progsoc.uts.edu.au/~geldridg/cpp/
[ Sorry about it's size..plans are afoot to break the sections ]
[ down. Also check out the ``What's New'' section there. ]
It has sections on Perl and Java (amongst many others). It also has
sections that describe the OO features mentioned above.
--
My own experience is that Perl is an excellent language to learn
about OO (and this comes from an Eiffel fan!). I have used these
OO features extensively to develop simple, reusable and extendible
``Date'' and ``Graphics'' packages over the last few months - the
results being accessible from:
http://www.tg.nsw.gov.au/sem/realtime/
Tom's ``Perltoot'' manual is all that was required - it comes
highly recommended.
I've tried to get into Java, but there's something less than
satisfying about it (sorry I can't quantify the reasons!!).
Hope this helps.
Geoff Eldridge
-- geldridg@progsoc.uts.edu.au
-- Eiffel Liberty Journal (elj):
-- http://www.progsoc.uts.edu.au/~geldridg/eiffel/liberty/
> Patrick O'Lone
> polone@sanasys.com
> polone@mcrest.edu
> "The edge is everything..."
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Sun, 12 Oct 1997 15:33:07 +0100
From: nguyent@uvil204.fr.ec.ps.net
Subject: Problem with unix command
Message-Id: <3440DFA3.812F5701@uvil204.fr.ec.ps.net>
Dear all,
I'm a new one in perl. Can somme one help me.
I want to execute the unix command "dfspace" but I don't why my my
perl script don't work with Netscape.
here is my script:
=========================================================
$buffer = $ENV{"QUERY_STRING"};
$flop = `echo $buffer|cut -d"=" -f2`;
@junk = `remsh $flop /usr/sbin/dfspace` ;
print "Content-type:text/html\n\n";
print <<EndOfHtml;
<html><head><title>Tester une commande UNIX </title></head>
<body>
<h2>Disk space: $flop </h2>
<hr>
EndOfHtml
;
print "<pre>";
print @junk;
print "</pre>";
=========================================================
Thanks in advance for your help.
Tung.
------------------------------
Date: Sun, 12 Oct 1997 22:30:40 +0100
From: hansmbg@algonet.se (Hans Malmberg)
Subject: Q: Dynamically creating hashes and arrays
Message-Id: <1997101222304015886@du46-152.ppp.algonet.se>
Now, let's see if I can explain this...
I'm trying ( I'll never leave that niveau..) to create
a Perl script which opens a file with data and manipulates
the data. The data file is built this way:
------------------------------------------
name1
date number number number
....... and more date + numbers
date number number number
name2
date number number number
....... and more date + numbers
date number number number
name3
date number number number
....... and more date + numbers
date number number number
-----------------------------------------
in the real world it looks like this
-----------------------------------------
S-E-Bankens Fond1
97-01-09 932,84 55,3848 16,8429
97-03-27 -115,97 -6,3767 18,1865
97-04-07 1231,34 70,3961 17,4916
97-10-07 1140,05 52,4168 21,7497
S-E-Bankens Teknofond
97-01-09 932,84 68,5388 13,6104
97-01-28 969,09 67,4929 14,3584
97-02-05 1231,34 83,5130 14,7443
97-03-05 1231,34 86,4238 14,2477
S-E-Bankens Eur Sbolagsfond
97-01-09 932,84 70,0599 13,3149
97-03-05 1231,34 84,0896 14,6432
97-03-27 -123,64 -8,1237 15,2197
97-09-30 -145,37 -8,8902 16,3517
S-E-Bankens Europafond
97-08-06 1140,05 95,0073 11,9996
97-09-05 1140,05 98,6680 11,5544
-----------------------------------------
I confess: I have a problem with hashes and lists,
and I think I'm too old to ever fully understand the
thing. But stubborn as I am I fight with trial and error.
this is the code I'm currently stuck with...
-----------------------------------------
open(FONDER,"P5451") || die "Can't Open Fonder Data File: $!\n";
@LINES = <FONDER>;
close(FONDER);
$SIZE = @LINES;
foreach $lines (@LINES) {
$_ = $lines;
if (length($_) == 1) { # empty line, just a linefeed
next;
}
$_ =~ s/\s*//; # strip leading spaces,
($datum, $inbelopp, $antal, $per_andel) = split(/\s+/,$_);
$rec = {}; # create empty array
if ( $datum =~ /S-E-B/ ) { # is it a date?
chop; # no it is the name of the fund
$rec->{$_} = $_; # store the name, named by itself
print "Test 1 rad 103 $_\n"; # just checkin'
push @MATRIS, $rec; # so the professionals say...
next; # the name is the only element
} # on this line
else { # continue, it's a date
$rec->{datum} = $datum; # store...
$rec->{antal} = $antal; # and so on
$rec->{per_andel} = $per_andel;
}
if ($inbelopp < 0) { # if negative then it cost's
$rec->{kostnad} = $inbelopp; # fee is kostnad
$avgifter += abs $inbelopp; # sum the fees
}
else {
$rec->{inbelopp} = $inbelopp; # input
}
push @MATRIS, $rec; # Programming Perl sid 268
} # end foreach
-----------------------------------------
It could be better, suggestions appreciated.
Now, I want a hash for each separate name, e.g. I
want to create a new hash for every new 'S-E-B...'-line.
The name of the hash shall be the name of the fund.
I have the book Perl Programming, but I have difficulties
interpreting some of the syntax.
If you can help I'm most grateful
Regards,
--
/Hans --- LUND 13.10'30(E 55.43'24(N
------------------------------
Date: Sun, 12 Oct 1997 10:04:09 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Replacing anything not matching with s/?
Message-Id: <ebohlmanEHxnyy.Dsy@netcom.com>
Mattias Lvnnqvist (mattias.lonnqvist@-NO-SPAM-.uidesign.se) wrote:
: foreach $line (split(/\n/, $wholist)) {
: $_=$line;
If you don't use a variable right after foreach, it will automatically
use $_.
: #strip out so only a-z, A-Z & blank remains
: # This does not do it, since it keeps everything not
: matching too...
: #s/[\w]+/$1/g;
Of course it doesn't do it. It says to replace any sequence of one or
more letters *or digits* with whatever is in $1 (and nothing's been put
there, since there are no parentheses in your regex).
: I've already tried checking perlsyn & perlop, with no success.
You want perlre.
------------------------------
Date: 12 Oct 1997 12:57:38 GMT
From: toutatis@_SPAMTRAP_toutatis.net (Toutatis)
Subject: Re: Replacing anything not matching with s/?
Message-Id: <toutatis-ya023180001210971457380001@news.euro.net>
In article <343B67D9.503700F7@-NO-SPAM-.uidesign.se>,
Mattias.Lonnqvist@-NO-SPAM-.uidesign.se wrote:
> I am trying to replace anything not matching a-z, A-Z, blank/space with
> nothing, eg
> getting a resulting string with only these chars.
> The following snippet is where I attempt to do it.
>
> foreach $line (split(/\n/, $wholist)) {
> $_=$line;
You could simply say: foreach(split etcetera){
$_ is automatically assigned the iteration value
> #strip out so only a-z, A-Z & blank remains
>
> # This does not do it, since it keeps everything not
> matching too...
> #s/[\w]+/$1/g;
When using $1, you should use braces around the match you want to be
represented. So s/(\w+)/$1/g; But then still this doen not do anything,
since you are substituting every match by itself, resulting in the same
string.
You could say s/\W//g; #replace every NON word character by nothing.
> # replace 1 or more space in a row with :
> s/\s+/:/g;
> @words=split(/:/);
> #do something with words
> }
Now since you have deleted all non word charcters in the first
substitution, don't expect this to work, because you don't have any spaces
left. So do it the other way round. First split (no need to substitue
splaces first):
@words = split /\s/;
Then remove the non word characters.
Or maybe more efficient (depending on what your input looks, and you ouput
should look like) all in one go:
@words = split /\W+/;
For better help next time quote some of you input, and describe your
desired output.
--
Toutatis
------------------------------
Date: Mon, 13 Oct 1997 02:02:58 +0900
From: Dan Kogai <dankogai@dan.co.jp>
To: Mattias.Lonnqvist@-NO-SPAM-.uidesign.se
Subject: Re: Replacing anything not matching with s/?
Message-Id: <34410296.7933@dan.co.jp>
Mattias L$Bvn(Jnqvist wrote:
> I am trying to replace anything not matching a-z, A-Z, blank/space
> with nothing, eg getting a resulting string with only these chars...
s/[^A-Za-z\s]//g;
# or
s/[^\w\s]//g; # but this one includes "_".
__END__
Dan the Camel Abuser
------------------------------
Date: Sun, 12 Oct 1997 10:28:40 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: SOLUTION: Are there problems using back quotes on Win95?
Message-Id: <ebohlmanEHxp3s.H34@netcom.com>
David Ransier (david_ransier@intercept.com) wrote:
: I finally figured out the problem. I'm guessing its due to the differences
: in the WinNT and Win95 command shells.
: The problem is how each command shell uses the slashes ( both "/" and "\")
: inside the back quotes.
Yep. Under 95, Win3.x and DOS, the command processor requires
backslashes as path separators (the filesystem itself does not), as
forward slashes are treated as option-introducers.
------------------------------
Date: Sun, 12 Oct 1997 11:55:27 -0400
From: Huron Internet <support@huron.net>
Subject: Telnet
Message-Id: <3440F2EF.50B936AE@huron.net>
I need to be able to telnet to a site and issue some commands. How do I
do this.
I do NOT want to use a module.
Any help would be appreciated :-)
Thanks...
------------------------------
Date: 12 Oct 1997 13:23:39 -0400
From: shawnw@bigwpi.WPI.EDU (Shawn Wagner)
Subject: Re: Telnet
Message-Id: <61r12r$oug$1@bigwpi.WPI.EDU>
In article <3440F2EF.50B936AE@huron.net>,
Huron Internet <support@huron.net> wrote:
>I need to be able to telnet to a site and issue some commands. How do I
>do this.
>
>I do NOT want to use a module.
>
Too bad, because Net::Telnet is designed do to exactly
what you want.
Anyways, you'll probably want to look at
man peripc, which has some example of socket code.
Oh, waitaminute... they use modules also (Socket or IO::Socket)
Looks like you're stuck... unless you like hardcoding your
own constants into the script. Can't help you there.
--
Shawn Wagner - shawnw@wpi.edu
http://mycroft.res.wpi.net/shawnw/
Narf!
------------------------------
Date: Sun, 12 Oct 1997 14:59:06 -0400
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Telnet
Message-Id: <-1210971459060001@aggie.coaps.fsu.edu>
In article <3440F2EF.50B936AE@huron.net>, Huron Internet
<support@huron.net> wrote:
+ I need to be able to telnet to a site and issue some commands. How do I
+ do this.
With a great deal of care. You could try:
open(TELNET," | telnet site") or die $!;
I've not done that, so I am unaware of any gotcha's. Or you can do your own
socket programming. But I've not done that, either. I use the Net::Telnet
module.
+ I do NOT want to use a module.
Why? Net::Telnet was written so that us (the rest of the world) wouldn't
have to learn to do socket programming. Why re-invent the wheel, when
its already been done??
Well, as they say: its your funeral.
James - Net::Telnet would have been my first suggestion...
--
Consulting Minister for Consultants, DNRC
Support the anti-Spam amendment <url:http://www.cauce.org/>
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/perl/faq/idiots-guide.html>
------------------------------
Date: 12 Oct 1997 08:07:04 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: Time?
Message-Id: <61qeh8$p1j@panix.com>
In <01bcd6bf$b71f2320$3c7237c0@rollanet.org.rollanet.org> "Mdoc" <mdoc@rollanet.org> writes:
>I am wondering how I would get the time from varous locations around the
>world, say China? Would I do it with GMT +/-, or another way? Any help
>would be appreciated!
Perl Modules are your friend.
Date::Format is a nice module:
#!/usr/local/bin/perl -w
use Date::Format;
# Print the time in different time zones
$edt_time = time2str('%T', time, 'EDT');
$pdt_time = time2str('%T', time, 'PDT');
print "It's $edt_time in New York and $pdt_time in Los Angeles.\n";
prints:
It's 14:51:16 in New York and 11:51:16 in Los Angeles.
Wanna know the timezone codes? Take a look at Time::Zone.
#!/usr/local/bin/perl -w
use Time::Zone;
for $num (-12 .. 13) {
$offset = $num * 3600;
$tz = tz_name("$offset");
print $num."00 $tz\n";
}
This program prints:
-1200 idlw
-1100 nt
-1000 cat
-900 hdt
-800 ydt
-700 pdt
-600 mdt
-500 cdt
-400 edt
-300 adt
-200 at
-100 wat
000 gmt
100 bst
200 mest
300 bt
400 zp4
500 zp5
600 zp6
700 wast
800 wadt
900 jst
1000 east
1100 eadt
1200 nzt
1300 nzdt
What's the offset from Greenwich Mean Time?
#!/usr/local/bin/perl -w
use Date::Format;
$tz = time2str('%Z', time);
$offset = time2str('%z', time);
print "The Timezone is $tz ($offset from GMT)\n";
prints:
The Timezone is EDT (-0400 from GMT)
You should be able to solve your problem with these tools. HTH,
--
Clay Irving <clay@panix.com> http://www.panix.com/~clay/
------------------------------
Date: Sun, 12 Oct 1997 10:22:55 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: truncate() & FileHandle(s)
Message-Id: <ebohlmanEHxou7.G9D@netcom.com>
Todd O'Boyle (oboyle@cs.purdue.edu) wrote:
: I need to truncate a file that I have a FileHandle on. perl's
: truncate() does not work, sending me a "No such file or directory" ($!)
: when I pass it
: my $fh = new FileHandle 'filename', 'r+';
: truncate($fh,0);
You haven't checked to see if opening the file failed. Put:
die "Couldn't open file: $!" unless defined $fh;
in between your two lines.
------------------------------
Date: Sun, 12 Oct 97 10:14:46 -0400
From: bsa@void.apk.net (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
Subject: Re: truncate() & FileHandle(s)
Message-Id: <3440dba0$2$ofn$mr2ice@speaker>
In <ebohlmanEHxou7.G9D@netcom.com>, on 10/12/97 at 10,
ebohlman@netcom.com (Eric Bohlman) said:
+-----
| : I need to truncate a file that I have a FileHandle on. perl's
| : truncate() does not work, sending me a "No such file or directory" ($!)
| : when I pass it
| : my $fh = new FileHandle 'filename', 'r+';
| : truncate($fh,0);
| You haven't checked to see if opening the file failed. Put:
+--->8
True, but not the problem; I saw this under Solaris 2.5, and *did* check all
relevant return values. truncate() was acting as if it had been handed a
filename instead of a filehandle.
--
brandon s. allbery [Team OS/2][Linux] bsa@void.apk.net
cleveland, ohio mr/2 ice's "rfc guru" :-) KF8NH
Warpstock '97: OS/2 for the rest of us! http://www.warpstock.org
Memo to MLS: End The Burn Scam --- Doug Logan MUST GO! FORZA CREW!
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 1163
**************************************