[24164] in Perl-Users-Digest
Perl-Users Digest, Issue: 6356 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 2 14:06:29 2004
Date: Fri, 2 Apr 2004 11:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 2 Apr 2004 Volume: 10 Number: 6356
Today's topics:
A file's directory <user@domain.invalid>
Re: A file's directory <jurgenex@hotmail.com>
Re: A file's directory <ittyspam@yahoo.com>
Re: bash shell script - perl conversion <ittyspam@yahoo.com>
Re: Boxed Perl or ActiveState Perl? (GreenLight)
cd status <a9807476@unet.univie.ac.at>
Re: cd status <nobull@mail.com>
Re: cd status <a9807476@unet.univie.ac.at>
Re: count files + dirs CORRECTED (GreenLight)
Re: count files + dirs (GreenLight)
eval() <toylet_at_mail.hongkong.com>
Re: eval() <toylet_at_mail.hongkong.com>
Re: eval() <nobull@mail.com>
Re: free source for bbs <dwall@fastmail.fm>
Re: free source for bbs <kirk@strauser.com>
Re: How do I do when handling the data (Anno Siegel)
Re: Lost data on socket - Can we start over politely? <jgibson@mail.arc.nasa.gov>
Modifying elements of an array <olusola.o.olaode@intel.com>
Re: multidimensional hash copy problem <nospam@nospam.org>
nfsbug in Perl (RJH)
Perl and Internet Explorer (akaliel)
Re: Perl and Internet Explorer <sbryce@scottbryce.com>
Sad experience with redirecting to /dev/null <mhunter@uclink.berkeley.edu>
Re: Sad experience with redirecting to /dev/null <mhunter@uclink.berkeley.edu>
Re: Sad experience with redirecting to /dev/null <tony_curtis32@_SPAMTRAP_yahoo.com>
Re: splitting string with unknown number of similar sub (GreenLight)
Re: Tough (for me) regex case <moggadah@hotmail.com>
Re: Tough (for me) regex case <moggadah@hotmail.com>
Re: Tough (for me) regex case <rob_perkins@hotmail.com>
Re: Why dosn't this work? <mail@annuna.com>
Re: Why dosn't this work? <ittyspam@yahoo.com>
Re: Why dosn't this work? <mail@annuna.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 02 Apr 2004 14:19:50 +0200
From: User At Domain Dot Invalid <user@domain.invalid>
Subject: A file's directory
Message-Id: <c4jlp7$qbi$1@ctb-nnrp2.saix.net>
Given a file name (possibl a path to it given as well), is there a way
to get or extract the name of the directory the file is in?
------------------------------
Date: Fri, 02 Apr 2004 12:21:43 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: A file's directory
Message-Id: <rVcbc.16948$BE3.8640@nwrddc03.gnilink.net>
User At Domain Dot Invalid wrote:
> Given a file name (possibl a path to it given as well), is there a way
> to get or extract the name of the directory the file is in?
Sure, just do a File::Find starting at /.
Remember, there may be many files with the same name.
jue
------------------------------
Date: Fri, 2 Apr 2004 08:34:15 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: A file's directory
Message-Id: <20040402083133.J19862@dishwasher.cs.rpi.edu>
On Fri, 2 Apr 2004, User At Domain Dot Invalid wrote:
> Given a file name (possibl a path to it given as well), is there a way
> to get or extract the name of the directory the file is in?
Assuming you're looking for the directory part of the path (so that a pure
filename would return "." as the directory):
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
my $dir = dirname($ARGV[0]);
print "Directory of $ARGV[0] is $dir\n";
__END__
Paul Lalli
------------------------------
Date: Fri, 2 Apr 2004 10:40:46 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: bash shell script - perl conversion
Message-Id: <20040402103825.Y19862@dishwasher.cs.rpi.edu>
On Fri, 1 Apr 2004, Peter Steele wrote:
> Hello all,
>
> I am trying to teach myself perl and I have a bash shell script which
> I
> thought might be a good "perl conversion exercise".
>
> While this is trivial with the shell, I have not yet gotten very far
> with perl.
>
> The "headers" file will contain ten lines of text, and the INFILE will
> typically be less than 50Kb in size.
>
> Any suggestions?
>
> Thank you all for your time.
>
> Script follows:
> ....................................................
> INFILE=$@
>
> while read header
> do
>
> echo "looking for $header in $INFILE"
> result=`grep -i $header $INFILE`
>
>
> done<headers
> ....................................................
>
Soooo, what exactly are you asking for? Are you asking us to write the
program for you? Doesn't that defeat the purpose of your trying to learn
Perl? You say you haven't gotten very far - well how far *have* you
gotten? Show us what you have, and tell us what problems you're having.
That way we can help correct you.
If you're just looking for a site to help you learn Perl, try
http://learn.perl.org
Paul Lalli
------------------------------
Date: 2 Apr 2004 09:48:36 -0800
From: google@milbaugh.com (GreenLight)
Subject: Re: Boxed Perl or ActiveState Perl?
Message-Id: <c4b60ce1.0404020948.3ff81d@posting.google.com>
Vittorio <victor@nospam.invalid> wrote in message news:<3hSac.965$hc5.16660@news3.tin.it>...
> On my dual-boot (linux debian testing & windows xp) box under linux I
> have installed debian testing and the deb perl 5.6 packages boxed with
> the debian distribution.
>
> Now, using perl both under linux and win xp I've installed activestate
> perl 5.8 under M$ win and it looks great!
>
> The same activestate site offer a debianized perl-5.8 package which is
> installed under usr/local/bin.
>
> In the opinion of more experienced users than I am is there any
> advantage for me to install activestate perl instead of the standard deb
> packages?
>
With ActiveState on Win32, they have the ppm tool which simplifies
package installation (no need to compile modules locally):
ppm install File-Slurp
Maybe they have the same thing for Debian. That would be one benefit
to switching, IMHO.
> Can both versions of perl coexist?
>
> If I install activestate perl, could I eliminate the boxed debian perl
> packages (to avoid duplication, of course) or they're essential for the
> installation?
>
I don't know anything about Debian (I use *BSD), so I cannot help you
there.
--
my real address is perl - at - milbaugh - dot - com
------------------------------
Date: Fri, 02 Apr 2004 13:29:22 +0200
From: Richard Neuboeck <a9807476@unet.univie.ac.at>
Subject: cd status
Message-Id: <406d4da4$0$18702$3b214f66@usenet.univie.ac.at>
Hi!
I'm trying to get some status information from my CDRW-drive and
CD-drive. In detail I would like to know whether a CD is inserted, what
kind of CD it is or if it's blank. I'm using perls ioctl function like this:
#!/usr/bin/perl
open (CD, "/dev/cdrom") || die "Can not access /dev/cdrom: $!";
$retval1 = ioctl(CD, 0x5326, 0); # CDROM_DRIVE_STATUS
$retval2 = ioctl(CD, 0x5327, 0); # CDROM_DISC_STATUS
$retval3=0;
$retval4 = ioctl(CD, 0x5305, \$retval3); # CDROMREADTOCHDR
close (CD);
#and some interpretation of the return values
This works fine with non blank CDs. If I insert a blank CD I can only
run this script once. Then I'm getting the following error message:
"Can not access /dev/cdrom: No medium found". At this point I can't even
use the tray-open script to eject the CD because the device can't be opened.
#!/usr/bin/perl
open (CD, "/dev/cdrom") || die "Can not access /dev/cdrom: $!";
ioctl(CD, 0x5309, 0);
close(CD);
Still working though is the eject C program which doesn't have a problem
opening the cdrom device. I still don't get it why perl is refusing to
open the device file more than once if a blank CD is inserted?
Am I doing something wrong?
Is there a better way to obtain some status information from the CD-drive?
Thanks in advance!
Richard
PS: By the way I tested the above scripts on RH9 (perl-5.8.0-88.3) with
an ATAPI CD-drive and on Debian/testing (perl-base 5.8.3-2) with a SCSI
CD-writer and SCSI CD-drive with the same results.
------------------------------
Date: 02 Apr 2004 12:33:20 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: cd status
Message-Id: <u9isgi62db.fsf@wcl-l.bham.ac.uk>
Richard Neuboeck <a9807476@unet.univie.ac.at> writes:
> This works fine with non blank CDs. If I insert a blank CD I can only
> run this script once. Then I'm getting the following error message:
> "Can not access /dev/cdrom: No medium found". At this point I can't
> even use the tray-open script to eject the CD because the device can't
> be opened.
>
> #!/usr/bin/perl
> open (CD, "/dev/cdrom") || die "Can not access /dev/cdrom: $!";
> ioctl(CD, 0x5309, 0);
> close(CD);
>
> Still working though is the eject C program which doesn't have a
> problem opening the cdrom device. I still don't get it why perl is
> refusing to open the device file more than once if a blank CD is
> inserted?
Stracing the eject program reveals that it uses open mode
O_RDONLY|O_NONBLOCK.
Perhaps you should try a sysopen() with that mode.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 02 Apr 2004 15:15:44 +0200
From: Richard Neuboeck <a9807476@unet.univie.ac.at>
Subject: Re: cd status
Message-Id: <406d6692$0$18702$3b214f66@usenet.univie.ac.at>
Brian McCauley wrote:
> Perhaps you should try a sysopen() with that mode.
Thanks a lot!
sysopen(CD, /dev/cdrom, O_RDONLY | O_NONBLOCK) solved my problems.
------------------------------
Date: 2 Apr 2004 09:35:34 -0800
From: google@milbaugh.com (GreenLight)
Subject: Re: count files + dirs CORRECTED
Message-Id: <c4b60ce1.0404020935.27b94463@posting.google.com>
use File::Slurp;
my $dir = 'd:/active/';
my ($file_count, $dir_count) = (0, 0);
my @file_array = read_dir($dir);
foreach my $file_name (@file_array) {
my $full_name = $dir . $file_name;
if (-f $full_name) {
$file_count++;
} elsif (-d $full_name) {
$dir_count++;
}
}
print "Files: $file_count\nDirectories: $dir_count\n";
--
my real address is perl - at - milbaugh - dot - com
------------------------------
Date: 2 Apr 2004 09:34:41 -0800
From: google@milbaugh.com (GreenLight)
Subject: Re: count files + dirs
Message-Id: <c4b60ce1.0404020934.582fb00d@posting.google.com>
use File::Slurp;
my $dir = 'd:/active/';
my ($file_count, $dir_count) = (0, 0);
my @file_array = read_dir($dir);
foreach my $file_name (@file_array) {
my $full_name = $dir . $file_name;
if (-d $full_name) {
$file_count++;
} elsif (-d $full_name) {
$dir_count++;
}
}
print "Files: $file_count\nDirectories: $dir_count\n";
--
my real address is perl - at - milbaugh - dot - com
------------------------------
Date: Fri, 02 Apr 2004 21:53:39 +0800
From: toylet <toylet_at_mail.hongkong.com>
Subject: eval()
Message-Id: <406d7030$1_3@rain.i-cable.com>
eval ( $dbh->do("DROP TABLE foo") );
print "dropped table foo\n" if $@;
The program execution stopped at eval(). ISn't it supposed to ignore errors?
--
.~. Might, Courage, Vision. In Linux We Trust.
/ v \ http://www.linux-sxs.org
/( _ )\ Linux 2.4.22-xfs
^ ^ 9:52pm up 7 days 14:06 load average: 1.00 1.01 1.00
------------------------------
Date: Fri, 02 Apr 2004 21:54:25 +0800
From: toylet <toylet_at_mail.hongkong.com>
Subject: Re: eval()
Message-Id: <406d705f$1_3@rain.i-cable.com>
toylet wrote:
> eval ( $dbh->do("DROP TABLE foo") );
> print "dropped table foo\n" if $@;
>
> The program execution stopped at eval(). ISn't it supposed to ignore errors?
>
here are the errors:
DBD::mysqlPP::db do failed: Unknown table 'foo' at ./mysql.pl line 15.
DBD::mysqlPP::db do failed: Unknown table 'foo' at ./mysql.pl line 15.
--
.~. Might, Courage, Vision. In Linux We Trust.
/ v \ http://www.linux-sxs.org
/( _ )\ Linux 2.4.22-xfs
^ ^ 9:52pm up 7 days 14:06 load average: 1.00 1.01 1.00
------------------------------
Date: 02 Apr 2004 17:36:13 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: eval()
Message-Id: <u98yhe5oci.fsf@wcl-l.bham.ac.uk>
toylet <toylet_at_mail.hongkong.com> writes:
> eval ( $dbh->do("DROP TABLE foo") );
> print "dropped table foo\n" if $@;
>
> The program execution stopped at eval(). ISn't it supposed to ignore errors?
You want eval{} not eval(). They do quite different things. BTW: For
what you are doing you don't need to know what eval() does but if
you are curious RTFM.
BTW: It would be more conventional to print "dropped table foo" if the
operation had _not_ failed.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 02 Apr 2004 14:37:57 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: free source for bbs
Message-Id: <Xns94BF61FCE8A9Cdkwwashere@216.168.3.30>
Uri Guttman <uri@stemsystems.com> wrote:
>>>>>> "TM" == Tad McClellan <tadmc@augustmail.com> writes:
>
> TM> I like the comment that Uri made once:
>
> TM> delimeter: noun, scale used to weigh and price cold cuts.
> TM> also the unit of length for salamis.
>
> i had forgotten about that one. i need to publish a dictionary :)
The Daemon's Dictionary?
------------------------------
Date: Fri, 02 Apr 2004 14:55:07 GMT
From: Kirk Strauser <kirk@strauser.com>
Subject: Re: free source for bbs
Message-Id: <877jwyh1o5.fsf@strauser.com>
=2D----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
At 2004-04-01T20:55:02Z, "Robin" <webmaster@infusedlight.net> writes:
> My latest bbs script written in perl is at www.infusedlight.net/bbs -
> please feel free to email me if you need help installing it or if you'd
> like to make a comment. Also, a working example is at
> www.infusedlight.net/design/bbs/bbs.pl
I particularly like the exchanges on the board, such as:
username of this user: foo
date of post: 03/17/04
name: Foo
email: foo@bar.com
post: You may wish to validate your HTML before getting to back-slappin'
happy:
http://validator.w3.org/check?uri=3Dhttp%3A%2F%2Fwww.infusedlight.net%2=
Fdesign%2Fbbs%2Fbbs.pl%3Faction%3Dview%26cat%3DDesign%26topic%3DDesign%2520=
talk%26user%3Dsysop
----------------------------------------
username of this user: sysop
date of post: 03/22/04
name: sysop
email: webmaster@infusedlight.net
post: Hmmm....validate my html, it doesn't post html.
and:
username of this user: robin
date of post: 03/18/04
name: Robin
email: robin@csf.edu
post: Don't listin to me! I don't know anything about programming!
Especially not Perl! In fact, I know so little that I left the source c=
ode
to this board freely available - the source code that shows how insecure
this site is - the source code that shows the location of the WORLD REA=
DABLE
password file!!! I KNOW NOTHING!!!
Robin. I speak seriously: drop this project like a hot potato. You are not
ready for what you're trying to do. Install something pre-made like phpBB
and move along. Really.
=2D --=20
Kirk Strauser
The Strauser Group
Open. Solutions. Simple.
http://www.strausergroup.com/
=2D----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFAbX5W5sRg+Y0CpvERAjUQAJ48uPiHll0ugdbEHt/whwMPakfXlACgjVnH
ZcYUIjBjXRrGamarlO1Dey8=3D
=3DLIgt
=2D----END PGP SIGNATURE-----
------------------------------
Date: 2 Apr 2004 11:34:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How do I do when handling the data
Message-Id: <c4jj3m$p0a$1@mamenchi.zrz.TU-Berlin.DE>
CatcherInTheRye <letnomanenterhere@yahoo.co.kr> wrote in comp.lang.perl.misc:
> Hi, How are you.
>
> I am a complete perl beginner.
> So, now I don't know how to handle efficiently the raw data to any data
> structure.
>
>
> 89 ;1;148;|89 ;2;316;|89 ;3;484;|45 ;1;142;|
> 45 ;1;142;|89 ;1;148;|33 ;2;258;| ; ; ;|
> 89 ;2;316;|89 ;3;484;|101;1;120;| ; ; ;|
> 89 ;3;484;|89 ;1;148;|89 ;2;316;|46 ;1;76 ;|
> 46 ;1;76 ;|67 ;2;248;|90 ;3;500;|33 ;2;258;|
> 33 ;2;258;|46 ;1;76 ;|45 ;1;142;|90 ;3;500;|
> 90 ;3;500;|91 ;3;372;|33 ;2;258;| ; ; ;|
> 91 ;3;372;|91 ;1;36 ;|42 ;3;446;|81 ;3;356;|
> 91 ;1;36 ;|101;1;120;|92 ;1;50 ;| ; ; ;|
> 92 ;1;50 ;|71 ;1;6 ;|72 ;3;370;|74 ;2;214;|
> 42 ;3;446;|42 ;1;110;|91 ;3;372;| ; ; ;|
> 101;1;120;|89 ;2;316;| ; ; ;| ; ; ;|
>
> Raw data shown above.
> I hope to check data validation each other data.
> Let me show you the meaning of data.
>
> "89 ;1;148" of first line is KEY and means CELL;SECTOR;PN
> and has its neighbor list like "89 ;2;316;|89 ;3;484;|45 ;1;142;|"
What kind of explanation is that? What's a "CELL", what's a "SECTOR",
what's a "PN", in what sense can such triplets be "neighbors", how do
these terms relate to each other, and what does it mean when an entry
is blank (as happens in the third and fourth column)?
This opens more questions than it answers.
> Other line has same meaning.
Oh, great!
> I hope to code the script to process following conditions.
What code? What have you tried so far?
> 1. Don't have same PN in the same line. If there is , print "Same PN in
> the '46 ;1;76 ' "
> 89 ;1;148;|89 ;2;316;|89 ;3;484;|45 ;1;142;|
> * * * *
> 2. Second field "89 ;2;316;" should be existed in the line where "89
> ;2;316;" is key.
> if there is not, print "89 ;1;148;" has "89 ;2;316;" but "89 ;2;316"
> don't have "89 ;1;148;".
> 89 ;1;148;|89 ;2;316;|89 ;3;484;|45 ;1;142;|
> +++++++++ *********
> 89 ;2;316;|89 ;1;149;|89 ;3;484;|101;1;120;|
> ********* +++++++++
We can help you with code you have, but we are not in the business
of writing programs to specification.
Anno
------------------------------
Date: Fri, 02 Apr 2004 09:31:33 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Lost data on socket - Can we start over politely?
Message-Id: <020420040931339533%jgibson@mail.arc.nasa.gov>
In article <406ae243.0@juno.wiesbaden.netsurf.de>, Thomas Kratz
<ThomasKratz@REMOVEwebCAPS.de> wrote:
>
> That depends ;-) The questions are:
>
> 1. Do I need more than SOMAXCONN simultaneous connections?
My understanding of the SOMAXCONN Unix kernel parameter is that it
refers to the maximum number of "unaccepted socket connections that can
be waiting in queue" (see for example
http://www.islandnet.com/~mark/somaxconn.html ).
Once the socket server program has done the accept on the incoming
socket connection request (listen()), the socket is removed from the
queue of waiting requests and is not restricted by the SOMAXCONN limit.
Therefore, it is possible to have more than SOMAXCONN connections, but
only up to SOMAXCONN waiting requests at any time. A typical value of
SOMAXCONN is 5, but web servers need to handle many more simultaneous
connections than that.
------------------------------
Date: Fri, 2 Apr 2004 13:35:29 -0500
From: "fenisol3" <olusola.o.olaode@intel.com>
Subject: Modifying elements of an array
Message-Id: <c4kbph$sho$1@news01.intel.com>
I assume the last element of my array has some junk characters attached to
it. So, how do I zap away all the junk characters after the very last
alphabet in my array? Thanks for helping out. Lets assume $headings[5] is
the last element of my array, I was thinking something like this:
"$headings1[5] =~ s/[a-zA-Z].*//;" but it doesn't work.
------------------------------
Date: Fri, 2 Apr 2004 09:38:29 -0500
From: "Christian Caron" <nospam@nospam.org>
Subject: Re: multidimensional hash copy problem
Message-Id: <c4jtt5$g1h1@nrn2.NRCan.gc.ca>
Thanks for your replies, I was just not sure if it was copying or making a
reference.
------------------------------
Date: 2 Apr 2004 10:22:47 -0800
From: anchor0057@yahoo.com (RJH)
Subject: nfsbug in Perl
Message-Id: <2a2566aa.0404021022.6cce5e2b@posting.google.com>
Has anybody attempted porting the functionality in the old nfsbug (NFS
security checker) command into Perl code? If so, would it be possible
to get a copy?
Thank you.
--
Bob
------------------------------
Date: 2 Apr 2004 09:25:43 -0800
From: akaliel@streamflo.com (akaliel)
Subject: Perl and Internet Explorer
Message-Id: <7123bc57.0404020925.2f5f99ab@posting.google.com>
Hi everyone, I'm having a problem with cgi perl scripts. We have a
perl based Intranet that contains mostly pdf documents. When a user
wants to view a file they simply click on a link and a perl script
figures out which file they want to view and streams it to their
browser. It works just fine for PDF's. The Acrobat plugin launches
and loads the file. However, we also have Powerpoint files on the
Intranet as well. These do not behave properly. What happens is the
Open/Save dialog comes up. If you click Save then it tries to save it
as a .pl file. If you click open Windows uses whatever program is set
in File Types to open .pl files (usually Notepad).
The only solution seems to be if you click Save and then manually
change the extension from .pl to .ppt. Which isn't a problem for me,
but the less computer savvy people around here can't handle it.
There aren't any problems in Netscape. It defaults the extension to
.ppt and clicking Open instead of Save launches Powerpoint correctly.
I know that Netscape works because it reads the MIME type correctly
(application/ppt), and IE doesn't work b/c in Microsoft's infinite
wisdom, they've programmed IE to ignore MIME types.
So I've deduced these as my options. I either need a Powerpoint
plugin that goes into the "Internet Explorer/plugin" directory, much
like that of Acrobat. Figure out how to get IE to READ my MIME types.
Or use some backhanded method to default the IE extension to .ppt for
Powerpoint files.
Note that I cannot simply rename my perl script to be .ppt instead of
.pl because then it wouldn't run at all. It has to be .pl.
Much help would be very appreciated. Thanks very much,
Allan
------------------------------
Date: Fri, 02 Apr 2004 11:03:12 -0700
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Perl and Internet Explorer
Message-Id: <106ramugpqvikf2@corp.supernews.com>
akaliel wrote:
> IE doesn't work b/c in Microsoft's infinite
> wisdom, they've programmed IE to ignore MIME types.
And that is the problem. It has nothing to do with Perl. There are some
headers you can send to try to clarify things for the browser, but IE
ignores those too.
------------------------------
Date: Fri, 2 Apr 2004 18:17:22 +0000 (UTC)
From: Mike Hunter <mhunter@uclink.berkeley.edu>
Subject: Sad experience with redirecting to /dev/null
Message-Id: <slrnc6rbds.qj.mhunter@celeste.net.berkeley.edu>
I just got through with a very painful debugging expierience:
...
system("iperf -s -D >/dev/null");
...
my $var = <STDIN>;
print "major screwage!" unless defined $var;
It prints "major screwage!"...*sigh*. If I take out the ">/dev/null", it
works fine.
I'm using FreeBSD 5.2.1-release with perl 5.6.1.
Please choose:
A) This is expected unix behavior; go back to windows, fungus!
B) This is a known bug
C) This is triggering a known bug in something else
D) You screwed up somewhere else
E) Write to Lary Wall immediately!
E) All of the above
------------------------------
Date: Fri, 2 Apr 2004 18:24:26 +0000 (UTC)
From: Mike Hunter <mhunter@uclink.berkeley.edu>
Subject: Re: Sad experience with redirecting to /dev/null
Message-Id: <slrnc6rbr4.qj.mhunter@celeste.net.berkeley.edu>
On Fri, 2 Apr 2004 18:17:22 +0000 (UTC), Mike Hunter wrote:
> I just got through with a very painful debugging expierience:
>
> ...
> system("iperf -s -D >/dev/null");
> ...
> my $var = <STDIN>;
> print "major screwage!" unless defined $var;
>
> It prints "major screwage!"...*sigh*. If I take out the ">/dev/null", it
> works fine.
I should have also said I tried switching to
fork || exec "iperf -s -D >/dev/null"
with the same results.
------------------------------
Date: Fri, 02 Apr 2004 12:25:36 -0600
From: Tony Curtis <tony_curtis32@_SPAMTRAP_yahoo.com>
Subject: Re: Sad experience with redirecting to /dev/null
Message-Id: <871xn65ja7.fsf@limey.hpcc.uh.edu>
>> On Fri, 2 Apr 2004 18:17:22 +0000 (UTC),
>> Mike Hunter <mhunter@uclink.berkeley.edu> said:
> I just got through with a very painful debugging
> expierience: ... system("iperf -s -D >/dev/null"); ... my
> $var = <STDIN>; print "major screwage!" unless defined $var;
> It prints "major screwage!"...*sigh*. If I take out the
> ">/dev/null", it works fine.
> I'm using FreeBSD 5.2.1-release with perl 5.6.1.
> Please choose:
> A) This is expected unix behavior; go back to windows,
> fungus!
Correct (well, the first part anyway :-). You are redirecting
all standard output from the command into a black hole. You
are then reading from a stdin that is completely unrelated to
the forked command.
I suspect you want to pipe the system() command instead:
open($fh, 'iperf... |') or die blah blah;
... read from $fh ...
close($fh) or die blah blah;
hth
t
------------------------------
Date: 2 Apr 2004 09:43:17 -0800
From: google@milbaugh.com (GreenLight)
Subject: Re: splitting string with unknown number of similar substrings
Message-Id: <c4b60ce1.0404020943.6d4044f1@posting.google.com>
"Jan Biel" <jan.biel@tu-clausthal.de> wrote in message news:<c4gq36$3s4$1@ariadne.rz.tu-clausthal.de>...
> Hi!
>
> I'm trying to split a string into an array of tokens. Some of the tokens are
> similar but I don't know how many will be in the string.
>
> Example: (just imagine \n instead of line breaks, this is really one string)
>
If the string has embedded newlines (\n), then why not split it out
into an array of lines (or read it into an array in the first place)?
@array = split/\n/, $table);
The individual lines might be easier to work with than trying to come
up with one (easily understandable) RE.
--
my real address is perl - at - milbaugh - dot - com
------------------------------
Date: Fri, 2 Apr 2004 17:01:14 +0200
From: "mortb" <moggadah@hotmail.com>
Subject: Re: Tough (for me) regex case
Message-Id: <OE#2YLMGEHA.2600@TK2MSFTNGP12.phx.gbl>
"(""|[^"])+"
gets me:
(1) "quick"
(2) "fox jumped ""over"" the"
- the | is an OR-operator which means that after " you match either "" or
any character except "
I've tried to get rid of the initial and ending quotes -- I think it's
possible in the same expression -- but I haven't succeeded -- yet.
tricky? -- yes!
/mortb
------------------------------
Date: Fri, 2 Apr 2004 17:16:00 +0200
From: "mortb" <moggadah@hotmail.com>
Subject: Re: Tough (for me) regex case
Message-Id: <OBFdpTMGEHA.3064@tk2msftngp13.phx.gbl>
...and
(?<=")(""|[^"])+(?=")
gets me...
(1) quick
(2) brown (notice the space before)
(3) fox jumped ""over"" the
this got rid of the quotes but introduced the " brown" error
Perhaps you can live with the quotes....
/mortb
"mortb" <moggadah@hotmail.com> wrote in message
news:OE%232YLMGEHA.2600@TK2MSFTNGP12.phx.gbl...
> "(""|[^"])+"
>
> gets me:
> (1) "quick"
> (2) "fox jumped ""over"" the"
>
> - the | is an OR-operator which means that after " you match either "" or
> any character except "
>
> I've tried to get rid of the initial and ending quotes -- I think it's
> possible in the same expression -- but I haven't succeeded -- yet.
> tricky? -- yes!
>
> /mortb
>
>
>
------------------------------
Date: Fri, 02 Apr 2004 15:35:39 GMT
From: Rob Perkins <rob_perkins@hotmail.com>
Subject: Re: Tough (for me) regex case
Message-Id: <ue1r60dtvjacn28rm7si4o8rfv89l55vc0@4ax.com>
>Perhaps you can live with the quotes....
Not really. I'm localizing an application. The regex is part of the
parser I'm using to identify string constants buried in the code, and
replace them with calls into a hashtable which uses the English string
as the source data for
I worked around it by taking the resulting match and using string
length and positioning data to remove the quotes. Not a big deal, but
I was hoping for something really regex-elegant. Everyone who loves
regex's seems to think it's possible, noone I know personally has
figured out how to do it quite yet...
Rob
------------------------------
Date: Fri, 02 Apr 2004 17:59:03 GMT
From: Joe <mail@annuna.com>
Subject: Re: Why dosn't this work?
Message-Id: <HRhbc.12600$lt2.11581@newsread1.news.pas.earthlink.net>
Paul Lalli wrote:
> On Tue, 30 Mar 2004, Joe wrote:
>
>
>>>>#spaces of the grid
>>>>
>>>>sub new{
>>>>
>>>>$space = {
>>>> char => "@",
>>>> tile => $_[0]
>>>> };
>>>>print $space->{tile}; <-- This prints /* OK */
>>>>bless $space, 'Space';
>>>>return $space;
>>>>}
>>>
>>>sub fchsym {
print "$space->{tile} \n"; <-- This does not print out
print "$space->{char} \n"; <-- This does
return $space->{tile};
}
>>>Please make your comments look like comments.
>>>In Perl, they start with #, not <--
>>>
>>>When does it print /* OK */? As far as I can tell, "new" never gets
>>>invoked.
>>
>>Yes it does, that is my constructor. My functions get invoked in my main
>>program. <-- arn't comments, they are where my problems and questions
>>are. I was just being graphic showing exactly why I am baffeled at why
>>I get the output I do.
>
>
> The point is that since you didn't *show* us your main program, we have no
> way of knowing what's happening when you're trying to call these
> functions. You haven't given anyone enough information to help you solve
> your problem. Please read the posting guidelines for this group, which
> say that you should post a small *but complete* program demonstrating the
> problem. You haven't given us a complete program from which to work.
>
> Paul Lalli
I will add the functions that access these functions. I realy don't
think that that is the problem. $space is global for the package. My
problem is that $space->{tile} dosn't cary from one function to another
in the package. $space->{char} carries over. $space->{tile} gets
filled but dosn't cary over to the fchsym function.
There are the commands that access the functions:
$board[$lp1][$lp2] = Space::new($map1[$lp1][$lp2]);
$chr = $maze->{level}->[$lp1][$lp2]->fchsym();
------------------------------
Date: Fri, 2 Apr 2004 13:17:13 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Why dosn't this work?
Message-Id: <20040402131423.T19862@dishwasher.cs.rpi.edu>
On Fri, 2 Apr 2004, Joe wrote:
> > The point is that since you didn't *show* us your main program, we have no
> > way of knowing what's happening when you're trying to call these
> > functions. You haven't given anyone enough information to help you solve
> > your problem. Please read the posting guidelines for this group, which
> > say that you should post a small *but complete* program demonstrating the
> > problem. You haven't given us a complete program from which to work.
> >
> > Paul Lalli
>
> I will add the functions that access these functions. I realy don't
> think that that is the problem. $space is global for the package. My
> problem is that $space->{tile} dosn't cary from one function to another
> in the package. $space->{char} carries over. $space->{tile} gets
> filled but dosn't cary over to the fchsym function.
>
> There are the commands that access the functions:
>
> $board[$lp1][$lp2] = Space::new($map1[$lp1][$lp2]);
>
> $chr = $maze->{level}->[$lp1][$lp2]->fchsym();
My god. LISTEN TO WHAT WE'RE SAYING. Post a SHORT BUT COMPLETE program.
This is not difficult. Don't tell us "I really don't think that's the
problem". If you *knew* the problem, you wouldn't be asking for help in
the first place. We're telling you what you need to do to let us help
you. If you're unwilling to do that, then you will not be helped. It's
as simple as that.
The point that $space is global to the package is likely the root cause of
your issue. Without seeing what's happening in the rest of your code, we
have no way of knowing what's happening to that global variable in between
method calls. POST THE WHOLE PROGRAM.
Paul Lalli
------------------------------
Date: Fri, 02 Apr 2004 18:30:16 GMT
From: Joe <mail@annuna.com>
Subject: Re: Why dosn't this work?
Message-Id: <Yiibc.12702$lt2.1108@newsread1.news.pas.earthlink.net>
Paul Lalli wrote:
> On Fri, 2 Apr 2004, Joe wrote:
>
>
>>>The point is that since you didn't *show* us your main program, we have no
>>>way of knowing what's happening when you're trying to call these
>>>functions. You haven't given anyone enough information to help you solve
>>>your problem. Please read the posting guidelines for this group, which
>>>say that you should post a small *but complete* program demonstrating the
>>>problem. You haven't given us a complete program from which to work.
>>>
>>>Paul Lalli
>>
>>I will add the functions that access these functions. I realy don't
>>think that that is the problem. $space is global for the package. My
>>problem is that $space->{tile} dosn't cary from one function to another
>>in the package. $space->{char} carries over. $space->{tile} gets
>>filled but dosn't cary over to the fchsym function.
>>
>>There are the commands that access the functions:
>>
>> $board[$lp1][$lp2] = Space::new($map1[$lp1][$lp2]);
>>
>> $chr = $maze->{level}->[$lp1][$lp2]->fchsym();
>
>
> My god. LISTEN TO WHAT WE'RE SAYING. Post a SHORT BUT COMPLETE program.
> This is not difficult. Don't tell us "I really don't think that's the
> problem". If you *knew* the problem, you wouldn't be asking for help in
> the first place. We're telling you what you need to do to let us help
> you. If you're unwilling to do that, then you will not be helped. It's
> as simple as that.
>
> The point that $space is global to the package is likely the root cause of
> your issue. Without seeing what's happening in the rest of your code, we
> have no way of knowing what's happening to that global variable in between
> method calls. POST THE WHOLE PROGRAM.
>
> Paul Lalli
I am looking through the rest of my program. I had a simmilar problem
with C++ simply because because I left of a & not maing an object a
refrence. I don't know why I assign a variable in one function and it
goes away in another. I would rather write this in C++ but I don't know
how to write GUI in C++ and I can't book to show me how. I have borland
but don't know how to use it. If you want it here is my whole program.
I have simmilar programs at my site www,annuna.com/perl5
package Player;
sub new { #player object constructor
$player = {
name => $_[0],
x => $_[1],
y => $_[2],
lv => $_[3],
xp => $_[4],
hp => $_[5],
mhp => $_[6],
wpn => $_[7],
arm => $_[8],
bag => $_[9]
};
bless $player, 'Player';
return $player;
}
sub generate { #player generator
my $name;
my $x=5;
my $y=5;
my $lv=1;
my $xp=70;
my $hp=12;
my $mhp = $hp;
my $wpn = 'none';
my $armor = 'none';
my @stuff = (['club','knife'],
['leather']);
my $bag = \@stuff;
print "What is your name:";
$name=<STDIN>; chomp $name;
$player = new ($name, $x, $y, $lv, $xp, $hp, $mhp, $wpn, $armor, $bag );
print "$player->{name} \n";
return $player;
}
####################################################################
package Space;
my $space;
#spaces of the grid
sub new{
$space = {
char => "A",
tile => $_[0]
};
print $space->{tile};
bless $space, 'Space';
return $space;
}
sub fchsym {
print "$space->{tile} \n";
print "$space->{char} \n";
return $space->{tile};
}
###################################################################
package Map;
my $sizex;
my $sizey;
my $maze;
my $play;
my %mov = ( nn => [ 0, -1],
ne => [ 1, -1],
nw => [ -1, -1],
ss => [ 0, 1],
se => [ 1, 1],
sw => [ -1, 1],
ee => [ 1, 0],
ww => [ -1, 0],
q => [ 0, 0],
i => [ 0, 0],
p => [ 0, 0],
d => [ 0, 0],
h => [ 0, 0]);
sub new{ #Reads the map to the spaces from a text file.
my $lp1;
my $lp;
$sizex = 17;
$sizey = 27;
my @map1 = (
[ qw (H H H H H H H H H H H H H H H H H H H H H H H H H H)],
[ qw (H . . . . H . . H . . . H H . . . . . . H . . . . H)],
[ qw (H H H H . H . H H . H . H . . . H . H . . . . H . H)],
[ qw (H . . . . . . . . . H . H . H . H H H . H H H H . H)],
[ qw (H . . H H . H H H . . . H . H . . . H . . . . H . H)],
[ qw (H . . H . . . H H . H . H . H H . H H H H H . H . H)],
[ qw (H H . H H . . H . . H . . . . . . . . . H H . H H H)],
[ qw (H H . . H . . . . . H H H H H . H H H . H H . . . H)],
[ qw (H . . H H H H H H . . . . . . . . H . . . . . H . H)],
[ qw (H . H H H . H H . . H H . H H H . H H . H . H H . H)],
[ qw (H . . . . . H . . H H . . . H . . . H H H . . H . H)],
[ qw (H H H H H . H H . H . . H H H . H . . . H . H H . H)],
[ qw (H . H . H . . H . H H . H . . . H H . H H . . . . H)],
[ qw (H . H . H . H H . . . . H H . H H . . . . . H H H H)],
[ qw (H . . . H . . H H H H . H . . H H H H H H . . . . H)],
[ qw (H H . H H . H H H . . . H H . . . . . . H H H . H H)],
[ qw (H . . . . . H H H H . H H H H H H H H . . . . . . H)],
[ qw (H H . H H . . . . . . . . . . H H H H H H H H . H H)],
[ qw (H H H H H H H H H H H H H H H H H H H H H H H X H H)]
);
for $lp1 (0 .. $sizex){
for $lp2 (0 .. $sizey){
$board[$lp1][$lp2] = Space::new($map1[$lp1][$lp2]);
}
}
$maze = {
xsize =>$sizex,
ysize =>$sizey,
level => \@board
};
$play = Player::generate();
bless $maze, 'Map';
return $maze;
}
sub move { # Moves the player accros the map.
my ($dir) = @_[1];
print "ff = $dir \n";
my $tx = $play->{x};
my $ty = $play->{y};
$tx = $tx + $mov{$dir}[0];
$ty = $ty + $mov{$dir}[1];
#move player to next space.
$maze->{level}->[$play->{x}][$play->{y}]->{char} = 0;
$play->{x} = $tx;
$play->{y} = $ty;
$maze->{level}->[$play->{x}][$play->{y}]->{char} = $play->{symbol};
showmap($tx, $ty);
}
sub showmap{
my ($xloc, $yloc) = @_;
my $lp1;
my $lp2;
my $chr;
print $maze->{level}->[3][3]->fchsym;
for $lp1 (($xloc - 1) .. ($xloc + 1)){
for $lp2 (($yloc -1) .. ($yloc + 1)){
$chr = $maze->{level}->[$lp1][$lp2]->fchsym();
print "x = $xloc y = $yloc : $chr \n";
} print "\n";
}
}
####################################################################
package Main;
#!/usr/bin/perl -w
use Tk;
use strict;
use integer;
use warnings;
my $author = 'Joe Creaney';
my $version = '2.0';
my $map = Map::new();
my $mw = MainWindow->new;
$mw->title("simple role Playing Gamey by ". $author. " version ". $version);
my $dirf = $mw->Frame(-background => 'Red',
-relief => 'groove')
->pack(-side => 'bottom');
$dirf->Button(-text=>"NW",-command => \&gonw)->grid(
$dirf->Button(-text=>"NN",-command => \&gonn),
$dirf->Button(-text=>"NE",-command => \&gone)
);
$dirf->Button(-text=>"W",-command => \&goww)->grid(
$dirf->Button(-text=>"Wait",-command => \&nogo),
$dirf->Button(-text=>"E",-command => \&goee)
);
$dirf->Button(-text=>"SW",-command => \&gosw)->grid(
$dirf->Button(-text=>"S",-command => \&goss),
$dirf->Button(-text=>"NE",-command => \&gone)
);
$mw->Button(-text=>"quit", -command=>\&bye)
->pack(-side=> 'right');
my $mapwin = $mw->Text(-width=>4,-height=>3)->
pack(-side=>'bottom');
MainLoop;
sub gonw{ $map->move('nw');}
sub gonn{ $map->move('nn');}
sub gone{ $map->move('ne');}
sub goww{ $map->move('ww');}
sub nogo{ $map->move('nw');}
sub goee{ $map->move('ee');}
sub gosw{ $map->move('sw');}
sub goss{ $map->move('ss');}
sub gose{ $map->move('sw');}
sub bye{exit}
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 6356
***************************************