[7585] in Perl-Users-Digest
Perl-Users Digest, Issue: 1211 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 21 21:08:21 1997
Date: Tue, 21 Oct 97 18: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 Tue, 21 Oct 1997 Volume: 8 Number: 1211
Today's topics:
Re: 2 element associate array (Tom Grydeland)
[Q] XSUB: how to make variable-length parameter lists O thalerj_NOSPAM@wwa._NOSPAM.com
catching exit() within eval() ??? <mallwitz@intershop.de>
Command Pipes in Perl Win32 (Craig Nastanski)
help needed on checking input buffer <webmaster@www.aquanet.gr>
help solving this beginning 'perl' program <JKOONTZ@dts.harris.com>
mkdir? <tamino@rebis.com>
Re: mkdir? (Faust Gertz)
Re: mkdir? <merlyn@stonehenge.com>
My perl 5.004_03 is buggy on this, can others please te Gerben_Wierda@RnA.nl
Re: Need help - Text formatting problems (Faust Gertz)
Re: non-greedy regexps <merlyn@stonehenge.com>
Re: Passing parameters to perl cgi script (Faust Gertz)
Re: Perl and DAO <youngej@magpage.com>
Perl5.003 source ??? <tbag@interlog.com>
Q: perl->NT ?? :( (Daryn Brightblade)
Re: Q: perl->NT ?? :( (Faust Gertz)
Take II, Program done, how 'bout some critiques/Improve (Thomas Munn)
Re: text wrap (Mike Rambour)
using wildcards with unlink command <reply-by@post.com>
Re: using wildcards with unlink command (Mike Heins)
Re: using wildcards with unlink command (Faust Gertz)
Re: Win32, del file? <joshb@kadence.kom>
Re: Win32, del file? (Mike Stok)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 21 Oct 1997 20:57:28 GMT
From: Tom.Grydeland@phys.uit.no (Tom Grydeland)
Subject: Re: 2 element associate array
Message-Id: <slrn64q5pn.8h0.Tom.Grydeland@mitra.phys.uit.no>
On Tue, 21 Oct 1997 17:01:47 GMT,
Mark Aurit <mark_aurit@NOSPAM.mail.northgrum.com> wrote:
> The book Im using (Teach Yourself perl 5... I know, its not the Camel
> book, but isnt bad) doesnt mention how to do this.
You may think it isn't. I think it is. See
<URL:http://xenu.phys.uit.no/~tom/TYP21D.html>
for why. The lack of a good description of multidimentional arrays (by
any name you choose to use for it) is one of the reasons I mention.
> A code snippet would be greatly appeciated.
$array[1][3] = "Hi"; # @array is an array containing references to
# anonymous arrays
$ref->[3][1] = "there"; # $ref is a reference to an anonymous array
# containing references to anonymous arrays
See the perllol manpage for the full story.
> Thanks, Mark
--
//Tom Grydeland <Tom.Grydeland@phys.uit.no>
------------------------------
Date: 21 Oct 1997 16:37:11 -0500
From: thalerj_NOSPAM@wwa._NOSPAM.com
Subject: [Q] XSUB: how to make variable-length parameter lists OUTPUT:s?
Message-Id: <62j7a7$8hi@miso.wwa.com>
I am trying to create an XSUB file that will provide an interface to
a special library function that behaves like a scanf. No, it hasn't
been done already, don't worry. This library is HP's SICL library,
which is used to control external instruments via serial port, GPIB,
or other connections.
Anyway, as you know, scanf takes a variable number of arguments, and
all the optional parameters are supposed to be OUTPUT: variables. Is
it possible to declare this? Or do I have to somehow call the scanf
function myself with these arguments and then push the results onto
the return stack and use it in a list format?
Feel free to point out any modules that do something similar. I'm
hoping I don't have to rewrite the scanf functionality similar to the
Scanf Module on CPAN.
---
-Jay Thaler
Remove _NOSPAM from my address above to email me, if you so desire.
------------------------------
Date: Tue, 21 Oct 1997 16:11:25 -0700
From: Christian Mallwitz <mallwitz@intershop.de>
Subject: catching exit() within eval() ???
Message-Id: <344D369D.83319413@intershop.de>
Hi folks,
I want to catch a call to exit() within a eval(). The code in eval is actually a
require(something) and I can't change "something" :-(
Here is was I tried:
eval "exit;";
warn "outside: [$@]" if $@;
print "finishing ...";
END { print "within END block\n"; }
As expected the END block is executed but not the print statement.
Is there any work around ?
Thanks a lot
Christian
------------------------------
Date: 21 Oct 1997 22:29:45 GMT
From: cnastans@mipos2.intel.com (Craig Nastanski)
Subject: Command Pipes in Perl Win32
Message-Id: <62jacp$bmu@scnews.sc.intel.com>
I'm running Perl 5.004 for WinNT 4.0 SP3.
I know that using command pipes (i.e. command1 | command2 | command3) is
inneficient in Win32. Unix handles this much better my running all the processes
in the pipeline concurrently and forwarding output of one to another as soon as
it becomes available. Win32 just uses temporary files (I've been told).
I have a script that uses a long command pipeline (7 commands or so piped together).
It took about 3 seconds on my HPUX box and now takes about 15 seconds on my win32 box.
Is there any way I can compensate for the innefficiencies of Win32's pipes? Can
I simulate the equivalent Unix behavior using Perl? Perl Win32 doesn't support
the fork command (why?) so I'm not sure if I can run the processes concurrently
and manage the output forwarding myself.
Any ideas?
--
+-----------------------------------------------------------------+
|Craig Nastanski cnastans@mipos2.sc.intel.com|
|U of Michigan '97 www-personal.engin.umich.edu/~naz|
+---------------------> Who is John Galt? <-----------------------+
------------------------------
Date: Wed, 22 Oct 1997 00:20:55 +0300
From: "Lefteris Xanthoudakis" <webmaster@www.aquanet.gr>
Subject: help needed on checking input buffer
Message-Id: <877468936.942674@pluto.hol.gr>
SGkgYWxsLA0KDQpJIHdhcyB3b25kZXJpbmcgaG93IEkgY2FuIGNoZWNrIHRoZSBpbnB1dCBidWZm
ZXIgaW4gYSBwcm9ncmFtIGJlZm9yZSB1c2luZyB0aGUgJ2dldGMnIGZ1bmN0aW9uLiBJZiBmb3Ig
ZXhhbXBsZSBJIGhhdmUgYSBsb29wIGluIHdoaWNoIHRoZSB1c2VyIGNhbiBwcmVzcyBhIHNwZWNp
ZmljIGtleSB0byBzdG9wLCB3aGF0IGZ1bmN0aW9uIHNob3VsZCBiZSB1c2VkIHRoYXQgZG9lcyBu
b3QgaW50ZXJydXB0IHRoZSBsb29wPw0KDQpUaGFuaydzLA0KTGVmdGVyaXMNCg0K
------------------------------
Date: Tue, 21 Oct 1997 15:16:41 -0700
From: Joyce Koontz <JKOONTZ@dts.harris.com>
Subject: help solving this beginning 'perl' program
Message-Id: <344D29C9.4F86@dts.harris.com>
Here is the question:
Write a "Perl" program that takes as input a momth and day, sucn as
"Dec 31".
The program should return what day of the year it is. Thus, "Jan 1"
should return 1, "Dec 31" should return 365 (you can assume February
has 28 days).
You may want to allow the use of full month names such as "January 28".
------------------------------
Date: 21 Oct 1997 21:37:12 GMT
From: Tim Meals <tamino@rebis.com>
Subject: mkdir?
Message-Id: <62j7a8$dkm$1@castor.dnai.com>
I apologize now if this is a simple question that I should be able to
figure out by myself. Maybe after a bite to eat things will make more
sense.
At any rate, I'm having problems with getting mkdir to create a
directory. The O'Reilly book, CORE Perl documentation and FAQs (that
I've found) have very little about how to use mkdir correctly. I've
tried all of the following:
mkdir($directory,"0776");
mkdir($directory,"ug+rwx,o+rx");
mkdir($directory,"00776");
mkdir($directory,"776");
I get different results with each one, but non give the permissions I
want, "drwxrwxr-x". Please help out with this simple little statement
that's driving me bonkers!
Perl version is 5.00401, OS is Solaris x86 2.5 or IRIX 5.2 (both have the
same problem).
--
Tim Meals
Electronic Marketing Specialist | "There can be no happiness,
Rebis Industrial Workgroup Software | except within yourself, in
tim.meals@rebis.com | your art."
http://www.rebis.com | -- Ludwig van Beethoven
------------------------------
Date: Tue, 21 Oct 1997 22:05:48 GMT
From: faust@wwa.com (Faust Gertz)
Subject: Re: mkdir?
Message-Id: <34562460.12353950@news.wwa.com>
On 21 Oct 1997 21:37:12 GMT, Tim Meals <tamino@rebis.com> wrote:
>At any rate, I'm having problems with getting mkdir to create a
>directory. The O'Reilly book, CORE Perl documentation and FAQs (that
>I've found) have very little about how to use mkdir correctly. I've
>tried all of the following:
>
>mkdir($directory,"0776");
>mkdir($directory,"ug+rwx,o+rx");
>mkdir($directory,"00776");
>mkdir($directory,"776");
>
>I get different results with each one, but non give the permissions I
>want, "drwxrwxr-x". Please help out with this simple little statement
>that's driving me bonkers!
Did you run perl -w? Did look at this question from the FAQ?
:Why isn't my octal data interpreted correctly?
:
:Perl only understands octal and hex numbers as such when they occur as literals in your program. If they are read in from
:somewhere and assigned, no automatic conversion takes place. You must explicitly use oct or hex if you want the values
:converted. oct interprets both hex (``0x350'') numbers and octal ones (``0350'' or even without the leading ``0'', like ``377''), while
:hex only converts hexadecimal ones, with or without a leading ``0x'', like ``0x255'', ``3A'', ``ff'', or ``deadbeef''.
:
:This problem shows up most often when people try using chmod, mkdir, umask, or sysopen, which all want permissions in
:octal.
:
: chmod(644, $file); # WRONG -- perl -w catches this
: chmod(0644, $file); # right
It would have also made sense to look up 'chmod ' in perlfunc manpage.
:NAME
:
:chmod - changes the permissions on a list of files
:
:
:
:SYNOPSIS
:
:chmod LIST
:
:
:
:DESCRIPTION
:
:Changes the permissions of a list of files. The first element of the list must be the numerical mode, which should probably be an
:octal number, and which definitely should not a string of octal digits: 0644 is okay, '0644' is not. Returns the number of files
:successfully changed. See also the oct manpage, if all you have is a string.
:
: $cnt = chmod 0755, 'foo', 'bar';
: chmod 0755, @executables;
: $mode = '0644'; chmod $mode, 'foo'; # !!! sets mode to --w----r-T
: $mode = '0644'; chmod oct($mode), 'foo'; # this is better
: $mode = 0644; chmod $mode, 'foo'; # this is best
Do you understand now?
Streben nach Wahrheit
Faust Gertz
Philosopher at Large
Yet another famous Proof of P
Hillary Putnam:
Some philosophers have argued that not-p, on the grounds that q.
It would be an interesting exercise to count all the fallacies in
this "argument". (It's really awful, isn't it?) Therefore p.
------------------------------
Date: 21 Oct 1997 17:06:59 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: tim.meals@rebis.com
Subject: Re: mkdir?
Message-Id: <8cu3eawti4.fsf@gadget.cscaper.com>
>>>>> "Tim" == Tim Meals <tamino@rebis.com> writes:
Tim> At any rate, I'm having problems with getting mkdir to create a
Tim> directory. The O'Reilly book, CORE Perl documentation and FAQs (that
Tim> I've found) have very little about how to use mkdir correctly. I've
Tim> tried all of the following:
Tim> mkdir($directory,"0776");
Tim> mkdir($directory,"ug+rwx,o+rx");
Tim> mkdir($directory,"00776");
Tim> mkdir($directory,"776");
You're gonna scream:
mkdir $dir, 0776;
Or, equivalently:
mkdir $dir, oct("776");
When Perl is looking at a string, it's *never* octal unless you tell
it specifically.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 314 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: Tue, 21 Oct 1997 20:42:58 GMT
From: Gerben_Wierda@RnA.nl
Subject: My perl 5.004_03 is buggy on this, can others please test?
Message-Id: <EIF5JM.ALD@RnA.NL>
The following program when called as ./test1.pl
=================================================================
#! /usr/local/bin/perl
# Protocol strings
*::t_tag = \"M";
*::d_tag = \"E";
*::error_protocol = \"2 Protocol error (missing $::t_tag: or $::d_tag: tag)";
# Directories and files
{
my $path = $0;
$path =~ m'([\w./]+)';
$path = $1; #untaint
$path =~ s'(/[^/]*)$''; # Keep path from script name
*::dbdir = \"$path";
# The place where the everything is found
my $port = 7777;
*::serverPort = \"$port";
}
*::gorddb_name = \"$::dbdir/gorddb";
*::gord_pidfile = \"$::dbdir/gord.pid";
*::mailspooldir = \"/usr/spool/mail";
warn "$::dbdir\n";
warn "$::gord_pidfile\n";
warn "$::gorddb_name\n";
=================================================================
produces
=================================================================
7777
7777/gord.pid
7777/gorddb
=================================================================
whereas it should produce
=================================================================
.
./gord.pid
./gorddb
=================================================================
If I remove the line
*::error_protocol = \"2 Protocol error (missing $::t_tag: or $::d_tag: tag)";
or if I remove the variables from that string it works as it should. Have I
discovered a perl bug or some strange working of the perl-guts? Or is my
version (which passed all the tests) buggy after all and have I discovered a
test to be added?
In addition to this error:
/$matchline/; # Force pattern compile
foreach my $headerline (@header) {
if ($headerline =~ //) { # Speed: use last compiled pattern
suddenly stopped working properly in the same program (with or without the
reference variable). I cannot use //, I must use an explicit /$matchline/.
I do not know if it is related but it looks like the symbol table is screwed
up.
Gerben_Wierda@RnA.nl (Gerben Wierda)
"If you don't know where you're going, any road will take you there"
Paraphrased in Alice in Wonderland, originally from the Talmud.
Renee: "Met veel koper maakt men hoempa." (After hearing Brahms'
Festouverture)
--
Gerben_Wierda@RnA.nl (Gerben Wierda)
"If you don't know where you're going, any road will take you there"
Paraphrased in Alice in Wonderland, originally from the Talmud.
Renee: "Met veel koper maakt men hoempa." (After hearing Brahms'
Festouverture)
------------------------------
Date: Tue, 21 Oct 1997 20:56:23 GMT
From: faust@wwa.com (Faust Gertz)
Subject: Re: Need help - Text formatting problems
Message-Id: <344e1009.7148378@news.wwa.com>
On Tue, 21 Oct 1997 11:49:25 -0600, eric@jmfilm.com (Eric Broach)
wrote:
>How do you take a text string, assigned to a variable, and strip the
>returns out of it?
I would do it like this.
$value =~ tr/\015\012//d;
But it is unclear that this is a very good way to do it. :-)
>Here's the situation. I have a form on a Web page that includes the user's
>name and address. The address box is a multi-line text box. Most users
>will probably fill it in like this:
>
>1234 Any Street
>Suite 1
>Anytown, Any State 54321
>U.S.A.
I don't advise relying on users to fill in any kind of box with
information formatted the way one thinks it should be formatted.
>I take the input, and write it to a tab-delimited text file that can be
>imported into a database or spreadsheet program. But in order for it to
>work, I need the address to all be on the same line. In other words, I
>need to remove the returns from the text string, but keep the rest of it.
Perhaps you should strip the tabs from the field first and then
replace the new lines with tabs.
$value =~ tr/\t//d;
$value =~ tr/\015\012/\t/s;
This, however, will not solve all the formatting problems you are
going to get with having the address as one big text box and
converting new lines to tabs.
>I looked in my PERL books, and tried some things, but they didn't work. I
>tried using "split," and removing all the "\r"'s, then "join"ing the array
>back into one string, but it didn't work - the returns were still there.
Yes. Very interesting. There have been other messages in this
newsgroup which have covered why those methods don't always work. You
can use DejaNews to find out why if you are interested. Also, my
method may not always work. You can check out DejaNews if you are
interested.
Streben nach Wahrheit
Faust Gertz
Philosopher at Large
"If only you had plead guilty! We can manage the guilty - it is
the innocent who escape us, who cause nothing but anarchy." --
Jean Cocteau's _Bacchus_
------------------------------
Date: 21 Oct 1997 12:56:01 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: Ashraf Ahmed <ashraf@apollo3.com>
Subject: Re: non-greedy regexps
Message-Id: <8c3eluyjou.fsf@gadget.cscaper.com>
>>>>> "Ashraf" == Ashraf Ahmed <ashraf@apollo3.com> writes:
Ashraf> Let's say I have a string like this,
Ashraf> "meeabmooabmuuabheheabyum"
Ashraf> -- -- -- --
Ashraf> and let's say that I want to find the (first) *shortest* sub-string
Ashraf> which starts with "ab" and ends with "ab". In this case, the returned
Ashraf> string should be
Ashraf> "abmooab"
Ahh... use the lazy quantifier:
print "meeabmooabmuuabheheabyum" =~ /(ab.*?ab)/;
Ashraf> The FAQ suggests using the perl5 non-greedy constructs, but I seem to
Ashraf> remember reading somewhere that one should be careful when using
Ashraf> these.
One should be careful in general. :-)
Ashraf> What should I be careful about when using the non-greedy
Ashraf> constructs?
You should be careful to do it right.
Ashraf> And is there some solution that works without using the
Ashraf> non-greedy constructs (which would also work in a language that
Ashraf> doesn't support these constructs)?
Not trivially. It's very easy to construct one that nearly works, but
that I can usually break.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 314 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: Tue, 21 Oct 1997 20:59:57 GMT
From: faust@wwa.com (Faust Gertz)
Subject: Re: Passing parameters to perl cgi script
Message-Id: <344f1735.8983807@news.wwa.com>
On Tue, 21 Oct 1997 21:39:21 +0200, Asbjorn Dankertsen
<dankert@nordi.no> wrote:
>I want to pass parameters to a perl cgi script using this syntax from a
>web page:
>
>http://www.somedomain.com/cgi-bin/somescript.pl?parameter=value
>
>Is this possible?
Yes.
>If so, how do I access the parameter/value in my script?
As you are not really asking a perl question, but a Common Gateway
Interface question, this should be asked in
comp.infosystems.www.authoring.cgi. I also imagine you should look at
both Lincoln Stien's CGI.pm
(http://www-genome.wi.mit.edu/ftp/pub/software/WWW/cgi_docs.html) and
Nick Kew's CGI FAQ (see below).
:0.3 Where to get this document
:
:The homes of this document on the Web are now
:* the WebThing Virtual Office, at http://www.webthing.com/
: URL http://www.webthing.com/tutorials/cgifaq.html
:* the Web Design Group, at http://www.htmlhelp.com/
: URL http://www.htmlhelp.com/faq/cgifaq.html
:
:NOTE - If you want to mirror the FAQ on your WWW site on a
:publicly-visible server, please make sure you keep it up-to-date.
:
:Other known sources are:
:
:(1) USENET: posted to newsgroups (TEXT)
: news:comp.infosystems.www.authoring.cgi
: news:comp.answers
: news:news.answers
:
:(2) RTFM and mirror sites (TEXT)
: ftp://rtfm.mit.edu/pub/usenet/news.answers/www/cgi-faq
:
:(3) RTFM WWW mirror sites, including (Partial HTML)
: Europe - http://www.cs.ruu.nl/cgi-bin/faqwais
: America - http://www.cis.ohio-state.edu/hypertext/faq/usenet/
:
:(4) By EMAIL from my autoresponder (HTML or TEXT)
: Send blank email to
: mailto:nick+cgi_text@webthing.com
: or
: mailto:nick+cgi_html@webthing.com
: (depending on which version you want)
:**** NOTE CHANGE FROM PREVIOUS AUTORESPONDER SETUP! ****
:
:(5) By EMAIL from the FAQserver at RTFM (TEXT)
: Send email to mailto:mail-server@rtfm.mit.edu with
: send usenet/news.answers/www/cgi-faq
: in the body of your message
HTH
Faust Gertz
Philosopher at Large
"Even the gods, for all they are called wise, are no more to be
trusted than fleeting dreams. Among the gods, no less than mortal
men, confusion reigns." -- Orestes, _Iphigenia in Taurus_
------------------------------
Date: 21 Oct 1997 22:33:39 GMT
From: Ed Young <youngej@magpage.com>
To: hobo@alumni.stanford.org
Subject: Re: Perl and DAO
Message-Id: <62jak3$ckc$0@204.179.92.57>
Stan Cheng wrote:
>
> I'm trying to access a MS Access database through perl... can anyone
> help me in figuring out how to do this either through OLE or with
> DAO....
How about ODBC? Below is a complete program, just change the details to
suit your database and needs:
#!perl
use strict;
use Win32::ODBC;
my ($DSN, $db, $SqlStatement, %Data);
$DSN = "CCC";
if (!($db = new Win32::ODBC($DSN)))
{
print "Error connecting to $DSN\n";
print "Error: " . Win32::ODBC::Error() . "\n";
exit;
}
$SqlStatement = <<EOS;
SELECT DISTINCTROW
CoursePacket.CourseNumber,
TermYear.TermYear,
CoursePacket.PerPacketPrice,
CoursePacket.Bin
FROM TermYear
INNER JOIN CoursePacket ON TermYear.TermYearID =
CoursePacket.TermYearID
WHERE (((CoursePacket.UniversityID)=1) AND ((TermYear.InBins)=Yes));
EOS
if ($db->Sql($SqlStatement))
{
print "SQL failed.\n";
print "Error: " . $db->Error() . "\n";
$db->Close();
exit;
}
while($db->FetchRow())
{
undef %Data;
%Data = $db->DataHash();
# ...process the data...
print "$Data{'CourseNumber'}~";
print "$Data{'TermYear'}~";
print "$Data{'PerPacketPrice'}" if $Data{'PerPacketPrice'};
print "~";
print "$Data{'Bin'}" if $Data{'Bin'};
print "\n";
}
$db->Close();
------------------------------
Date: 21 Oct 1997 22:59:02 GMT
From: David Mayerlen <tbag@interlog.com>
Subject: Perl5.003 source ???
Message-Id: <62jc3m$lle$1@news.interlog.com>
Hi,
I can't seem to find the source for perl5.003 anywhere. I need to recompile
my AIX perl executable. Obviously something has been deemed wrong with
perl5.003 because it can no longer be found in CSPAN but perl5.002 and
perl5.004 are available!
Thanks in advance.
********************************************************************
* David Mayerlen +--------------------------+
* The Canadian Speculator | http://www.specstock.com |
* webmaster@specstock.com +--------------------------+
* 416.410.6679
********************************************************************
------------------------------
Date: Wed, 22 Oct 1997 04:59:20 GMT
From: daryn@solamnia.demon.co.uk (Daryn Brightblade)
Subject: Q: perl->NT ?? :(
Message-Id: <877467551.12106.0.nnrp-08.c2de12b5@news.demon.co.uk>
Quick question..
how can I convert a perl script, with unix directory structures
ie
open (SECTOR "/data/blah/blooh/bleeh");
to an NT directory structure
ie
open (SECTOR "c:\data\blah\blooh\bleeh");
please?
It's confusing the hell out of me
thank you very very very much
*poor idiotic perl newbie who needs this for new job :( *
ta
Daryn Brightblade
Comrades in Arms, Brothers in Peace, the Clan Brightblade
http://www.solamnia.demon.co.uk/
------------------------------
Date: Tue, 21 Oct 1997 21:47:51 GMT
From: faust@wwa.com (Faust Gertz)
Subject: Re: Q: perl->NT ?? :(
Message-Id: <344d1f7c.11102100@news.wwa.com>
On Wed, 22 Oct 1997 04:59:20 GMT, daryn@solamnia.demon.co.uk (Daryn
Brightblade) wrote:
>Quick question..
>how can I convert a perl script, with unix directory structures
>ie
>open (SECTOR "/data/blah/blooh/bleeh");
>to an NT directory structure
>ie
>open (SECTOR "c:\data\blah\blooh\bleeh");
>please?
You can convert it the wrong way, which is just what you did, or you
can convert it without making a mistake that is well documented in the
Frequently Asked Questions (http://language.perl.com/faq/index.html),
:Why can't I use "C:\temp\foo" in DOS paths? What doesn't
:`C:\temp\foo.exe` work?
:Whoops! You just put a tab and a formfeed into that filename! Remember that within double quoted strings (``like\this''), the
:backslash is an escape character. The full list of these is in Quote and Quote-like Operators. Unsurprisingly, you don't have a file
:called ``c:(tab)emp(formfeed)oo'' or ``c:(tab)emp(formfeed)oo.exe'' on your DOS filesystem.
:
:Either single-quote your strings, or (preferably) use forward slashes. Since all DOS and Windows versions since something like
:MS-DOS 2.0 or so have treated / and \ the same in a path, you might as well use the one that doesn't clash with Perl -- or the
:POSIX shell, ANSI C and C++, awk, Tcl, Java, or Python, just to mention a few.
I would be inclined to both single-quote literal strings and use
forward slashes.
>It's confusing the hell out of me thank you very very very much
>*poor idiotic perl newbie who needs this for new job :( *
So where is my cut of your salary for helping you out with your job?
Also, where is the cut for the collective wisdom which brought us the
FAQ?
Streben nach Wahrheit
Faust Gertz
Philosopher at Large
"You cannot solve the problem with the same kind of thinking that has
created the problem." - Albert Einstein
------------------------------
Date: Tue, 21 Oct 1997 23:50:47 GMT
From: munn@bigfoot.com (Thomas Munn)
Subject: Take II, Program done, how 'bout some critiques/Improvements?
Message-Id: <62jf72$nrg$1@nu-informer.alliance.net>
I have (with the help of this wonderful group) just completed my first
"useful" perl program. And it SORT of works on some of the datafiles. It is
supposed to parse a text file for certain fields & then output it to a comma
delimited format. It worked on my first testfile, but when I tested it on my
second (and larger) file, it messed up. I am using the split function to
split up an array, and then (by trial and error) finding out which elements
get assigned to which array and then assiging a variable to this. Here is the
code: Any way to refine this so that the fields remain constant (e.g. any
better way to filter out spaces. here is the example datafile (shortened for
your convenience that doesn't work:
Date Created and Mailed
Tue Oct 21 00:00:15 EDT 1997
Remaining mail messages in Interlock mail queue
18
Interlock gateway mail report summary
Totals
Unique Sender/Recipients: 3907
Total Messages Processed (in and out): 4912
Bytes Sent: 109095288 bytes
Bytes Rcvd: 125773067 bytes
Inbound Messages: 2875 (66729966 bytes)
Outbound Messages: 2037 (59043101 bytes)
Here is the final output from the program:
(the file that it
creates...)10/21/1997,109095288,125773067,2875,bytes),2037,bytes),
patrick.w.shaunnessy@... I truncated it for your convenience. As you can
see, it isn't assigning things the way that they should..
Now the Code:
months=('Jan', 1, 'Feb', 2, 'Mar', 3, 'Apr', 4, 'May', 5, 'Jun', 6,
'Jul', 7, 'Aug', 8, 'Sep', 9, 'Oct', 10, 'Nov', 11, 'Dec', 12);
while(<>) {
chomp;
if(m/Mon|Tue|Wed|Thu|Fri|Sat|Sun/) {
@fields=split(/ /);
$DayOfMonth=$fields[2];
$Year=$fields[5];
#$Year=~s/^..//; #I'd prefer to ditch this and keep 4 digit dates.
$Month=$months{$fields[1]};
$OutPutDate="$Month/$DayOfMonth/$Year";
#print "Date: $OutPutDate,\n";
}
if(m/Bytes Sent:/) {
s/\s{2,}//;
@fields=split(/ /);
$BytesSent=$fields[2];
#print "Bytes Sent: $BytesSent\n";
}
if (m/Bytes Rcvd:/) {
s/\s{2,}//;
@fields=split(/ /);
$BytesRecieved=$fields[2];
#print "Bytes Recieved: $BytesRecieved\n";
}
if (m/Inbound Messages:/) {
s/\s{2,}//;
@fields=split(/ /);
$MessagesIn=$fields[3];
$fields[5] =~ s/(\()//;
$MessageBytesIn=$fields[5];
#print "Messages in: $MessagesIn\n";
#print "Messages Bytes In: $MessageBytesIn\n";
}
if (m/Outbound Messages:/) {
s/\s{2,}//;
@fields=split(/ /);
$MessagesOut=$fields[2];
$fields[4] =~ s/(\()//;
$MessageBytesOut=$fields[4];
#print "Messages Out: $MessagesOut\n";
#print "Messages Bytes Out: $MessageBytesOut\n";
}
if (m/Inbound Mail Statistics/) {
@InBoundTopUser="a";
for ($i=0;$i<=16;++$i) {
$_=<>;
chomp;
/[A-Za-z0-9\-\.\(\)\!\|\*\:\$_]*@/;
#/,[\S]{1,].*@/;
$InBoundTopUser[$i]=$&.$';
#print "User Number $i: is $InBoundTopUser[$i]\n";
}
}
if (m/Mail Statistics/) {
@MailTopUser="a";
for ($i=0;$i<=16;++$i) {
$_=<>;
chomp;
/[A-Za-z0-9\-\.\(\)\!\|\*\:\$_]*@/;
#/,[\S]{1,].*@/;
$MailTopUser[$i]=$&.$';
#print "User Number $i: is $MailTopUser[$i]\n";
}
}
}
open (OUT, ">>merge.csv");
print OUT "$OutPutDate,$BytesSent,$BytesRecieved,$MessagesIn,$MessageBytesIn";
print OUT
",$MessagesOut,$MessageBytesOut,$InBoundTopUser[3],$InBoundTopUser[4]";
print OUT
",$InBoundTopUser[5],$InBoundTopUser[6],$InBoundTopUser[7],$InBoundTopUser[8],
";
print OUT
"$InBoundTopUser[9],$InBoundTopUser[10],$InBoundTopUser[11],
$InBoundTopUser[12]";
print OUT
",$MailTopUser[3],$MailTopUser[4],$MailTopUser[5],$MailTopUser[6],
$MailTopUser[7]";
print OUT
",$MailTopUser[8],$MailTopUser[9],$MailTopUser[10],$MailTopUser[11],
$MailTopUser[12]\n";
close (OUT);
------------------------------
Date: Tue, 21 Oct 1997 21:06:05 GMT
From: me@no-spam.com (Mike Rambour)
Subject: Re: text wrap
Message-Id: <62j5ej$qi7@daffy.sb.west.net>
nem@abattoir.cc.ndsu.nodak.edu (Nem W Schlecht) wrote:
>[courtesy copy e-mailed to author(s)]
>In comp.lang.perl.misc, Mike Rambour <name@server.com> wrote:
>> I am trying to make the text::wrap module work, but I dont have
snip...
Thank you, Nem. Its working just beautifully.
I spent way too much time trying to do this, you saved me lots and
lots of hours of work.
mike
mikey at inline-tech dot com
soon to be mikey at singercars dot com (anyday now)
(replace at with @ and replace dot with . to reply)
And for you automated email spammers out there, here's the email addresses
of the current board of the Federal Communications Commission:
Chairman Reed Hundt: rhundt@fcc.gov
Commissioner James Quello: jquello@fcc.gov
Commissioner Susan Ness: sness@fcc.gov
Commissioner Rachelle Chong: rchong@fcc.gov
And let's help you send some spam to the USPS, too:
customer@email.usps.gov
------------------------------
Date: Tue, 21 Oct 1997 17:45:55 -0500
From: "Paul B." <reply-by@post.com>
Subject: using wildcards with unlink command
Message-Id: <62jbd7$u6$1@insosf1.netins.net>
Is it possible to use a wildcard with an unlink command? Like:
unlink ("/test/web/*.txt");
I've tried that and it dosn't seem to work. If I substitute an actual
filename, it'll work. If one kind person would point me in the right
direction, I would greatly appreciate it.
thanxs to anyone who can help. :-)
------------------------------
Date: 21 Oct 1997 23:41:58 GMT
From: mheins@prairienet.org (Mike Heins)
Subject: Re: using wildcards with unlink command
Message-Id: <62jek6$kit$1@vixen.cso.uiuc.edu>
Paul B. (reply-by@post.com) wrote:
: Is it possible to use a wildcard with an unlink command? Like:
:
: unlink ("/test/web/*.txt");
:
: I've tried that and it dosn't seem to work. If I substitute an actual
: filename, it'll work. If one kind person would point me in the right
: direction, I would greatly appreciate it.
:
That is because unlink doesn't do that -- it is quite
specifically stated in the docs, as I recall.
In later Perl versions, I think you can do:
unlink glob "whatever.*";
--
Regards,
Mike Heins
This post reflects the
opinion of my employer.
------------------------------
Date: Wed, 22 Oct 1997 00:24:32 GMT
From: faust@wwa.com (Faust Gertz)
Subject: Re: using wildcards with unlink command
Message-Id: <344d4316.6389590@news.wwa.com>
On Tue, 21 Oct 1997 17:45:55 -0500, "Paul B." <reply-by@post.com>
wrote:
>Is it possible to use a wildcard with an unlink command?
Yes, it is possible to use a "wildcard" with an unlink function.
>Like:
>
>unlink ("/test/web/*.txt");
>
>I've tried that and it dosn't seem to work.
I'm not surprised. :-) I have no idea why you think this would work.
Think about the differences between a scalar and list context. When
you do, I think you will see that what you meant to write was:
unlink <./test/web/*.txt>;
If you still don't get it, look in the perlfunc manpage.
:NAME
:
:unlink - remove one link to a file
:
:
:
:SYNOPSIS
:
:unlink LIST
:
:unlink
:
:
:
:DESCRIPTION
:
:Deletes a list of files. Returns the number of files successfully deleted.
:
: $cnt = unlink 'a', 'b', 'c';
: unlink @goners;
: unlink <*.bak>;
:
:Note: unlink will not delete directories unless you are superuser and the -U flag is supplied to Perl. Even if these conditions are
:met, be warned that unlinking a directory can inflict damage on your filesystem. Use rmdir instead.
:
:If LIST is omitted, uses $_.
If you still don't get it, try looking at the perldata manpage
(Especially the 'Context' subsection). If that doesn't do the trick,
ask again.
Streben nach Wahrheit
Faust Gertz
Philosopher at Large
------------------------------
Date: Tue, 21 Oct 1997 13:51:14 -0700
From: "Josh Baudhuin" <joshb@kadence.kom>
Subject: Re: Win32, del file?
Message-Id: <62j4k5$k2m$1@news.cadence.com>
unlink() generally works.
The Win32 ports won't delete a file if it is marked read-only (or, probably,
system/hidden, either).
So, you have to chmod it to make it deletable, and then delete it. You can
override unlink to do all that stuff if you want it to work nicely.
Eric wrote in message <344cf227.12703683@intXnt>...
>Another Perl beginer question:
>
>How the heck am I supposed to delete files from Perl? The only way I can
>rig is to send a DOS command out from Perl in a print command with the ``
>marks around it. What is the easier way I have missed?
>
>I am using the Win32 307, bld 310 version of Perl on NT 3.51 server.
>
>Thanks!
>
>
>eric@intiman.org_nospam
>Eric Kylstra
>Computer Coordinator
>Intiman Theatre
>
>I have the nospam on the end of my email address for the obvious reason.
>Remove it to email me directly.
------------------------------
Date: 21 Oct 1997 20:55:54 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Win32, del file?
Message-Id: <62j4sq$jmi@news-central.tiac.net>
In article <344cf227.12703683@intXnt>, Eric <eric@intiman.org_nospam> wrote:
>Another Perl beginer question:
>
>How the heck am I supposed to delete files from Perl? The only way I can
>rig is to send a DOS command out from Perl in a print command with the ``
>marks around it. What is the easier way I have missed?
>
>I am using the Win32 307, bld 310 version of Perl on NT 3.51 server.
Have you tried unlink ? It is the name of the unix call which removes a
link to a file (and if it's the last link the file is deleted.) The
perlfunc man page says:
unlink LIST
unlink Deletes a list of files. Returns the number of
files successfully deleted.
$cnt = unlink 'a', 'b', 'c';
unlink @goners;
unlink <*.bak>;
Note: unlink will not delete directories unless
you are superuser and the -U flag is supplied to
Perl. Even if these conditions are met, be warned
that unlinking a directory can inflict damage on
your filesystem. Use rmdir instead.
If LIST is omitted, uses $_.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
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 1211
**************************************