[17568] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4988 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 29 14:07:29 2000

Date: Wed, 29 Nov 2000 11:05:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <975524713-v9-i4988@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 29 Nov 2000     Volume: 9 Number: 4988

Today's topics:
        ANNOUNCE: Pod::XML <matt@sergeant.org>
    Re: Compile script to exe on many platforms <xzrgpnys@yvtugubhfrovm.pbz>
    Re: Compile script to exe on many platforms (Abigail)
    Re: Dates in perl (Chris Fedde)
    Re: Dates in perl (Tim Faitsch)
        Extracting substrings from strings <eT@quidel.com>
    Re: for each file in dir ? (Tad McClellan)
    Re: how do i direct compiler errors to a file-newbie <bart.lateur@skynet.be>
    Re: how do i direct compiler errors to a file-newbie <joe+usenet@sunstarsys.com>
    Re: how do i direct compiler errors to a file-newbie <geoff-at-farmline-dot-com@127.0.0.1>
        How do I null terminate a string ? <neil@alaweb.com>
        IIS CGI <ioa@sererico.com>
    Re: lynx with PERL (Tad McClellan)
        one question about perl return value <wangbill18@hotmail.com>
    Re: one question about perl return value simbean@my-deja.com
        Pattern matching in arrays with foreach loop konstantin_wiesel@my-deja.com
        Pattern matching in arrays with foreach loop konstantin_wiesel@my-deja.com
    Re: Poll it (Tad McClellan)
    Re: Reading a csv file <jeff@vpservices.com>
    Re: Regex question about \x$1 (Tad McClellan)
    Re: Regex to zero pad an IP address (Craig Berry)
    Re: running Perl program on NT and accessing a UNIX mac <Petri_member@newsguy.com>
        Search & Replace <k s t 3 i n w 3 @ u s v i s i 0 n . c 0 m>
        sockets and threads simbean@my-deja.com
    Re: splitting a string into an array and preserving the <bernie@fantasyfarm.com>
    Re: splitting a string into an array and preserving the (Tom Christiansen)
    Re: system() and backticks working intermittently on Tr (Villy Kruse)
        using Filter:: directly from perl binary <jim_NOSPAM_@gosquad.com>
    Re: working with lists of associative arrays (Tad McClellan)
        XS and C++ <isterin@hotmail.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 29 Nov 2000 16:35:36 +0000
From: Matt Sergeant <matt@sergeant.org>
Subject: ANNOUNCE: Pod::XML
Message-Id: <t2ac6ubadgnda1@corp.supernews.com>

Pod::XML has been uploaded to the CPAN. It uses Pod::Parser to
generate XML from Pod. Also included is a simple pod2xml script.

Pod::XML converts =head instructions to sections, and takes care to
nest sections, so that =head2's come within the section created by
=head1. It is also careful about nesting =item lists. The following
are the relevant mappings it produces:

The first =head1 creates the <title> in the <head> section. If the
first =head1 is "NAME", then it takes the first paragraph following
that as the document title.

Subsequent =head1's create <sect1> tags. The text of the heading goes
in the <title> child element.

=headN creates <sectN>, where N is 1..4.

Verbatim (indented) sections create <verbatim> elements. Rather than
use XML escaping, Pod::XML uses CDATA sections so that perl code that
uses the <, & and > characters still looks readable.

Ordinary paragraphs of text create <para> elements.

=over creates a <list> tag.

=back creates a </list> tag.

=item creates a <listitem> tag. If there is text after the =item, it
creates a <itemtext> element containing the text, after stripping the
text of a leading * character.

C<> creates <code> elements.

S<> turns spaces into the unicode character #160 (equivalent to &nbsp;
in HTML).

B<> creates <strong> elements.

I<> creates <emphasis> elements.

E<> escapes are properly expanded.

L<> creates a <link> element, although this needs expanding to extract
the contents of the link to make more sense.

Enjoy, feedback welcome.

Matt.




------------------------------

Date: 29 Nov 2000 18:55:58 GMT
From: kevin metcalf <xzrgpnys@yvtugubhfrovm.pbz>
Subject: Re: Compile script to exe on many platforms
Message-Id: <3A2551CA.DFBAE0F8@yvtugubhfrovm.pbz>

Abigail wrote:
> On Tue, 28 Nov 2000 15:22:41 -0500, Neb (berube@odyssee.net) wrote in comp.lang.perl.misc <URL: news:<DsUU5.275$s8.21196@news.globetrotter.net>>:
> ++ Hi,
> ++
> ++ I have a script that I want to compile to exe on different platform (Unix
> ++ and Windows).  Is it possible?
> 
> On Unix, you would use "cp" (compile perl).
>     # cp program.pl program.exe
> Abigail

This is just disturbing.

--
email: xzrgpnys@yvtugubhfrovm.pbz
Huh?  http://www.flactem.com/utils/rot13.html


------------------------------

Date: 29 Nov 2000 17:18:36 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Compile script to exe on many platforms
Message-Id: <slrn92aejb.mnq.abigail@tsathoggua.rlyeh.net>

On Tue, 28 Nov 2000 15:22:41 -0500, Neb (berube@odyssee.net) wrote in comp.lang.perl.misc <URL: news:<DsUU5.275$s8.21196@news.globetrotter.net>>:
++ Hi,
++ 
++ I have a script that I want to compile to exe on different platform (Unix
++ and Windows).  Is it possible?


On Unix, you would use "cp" (compile perl).

    # cp program.pl program.exe



Abigail


------------------------------

Date: Wed, 29 Nov 2000 16:05:34 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Dates in perl
Message-Id: <iP9V5.3$_g6.189586944@news.frii.net>

In article <903673$vc7$1@nnrp1.deja.com>,  <ricki.stern@med.nyu.edu> wrote:
>I need to find out the number of days between two dates. One idea I
>thought up for soing this is to use the localtime function and then
>take out the yday and subtract one yday from the other.
>
>Is there a better way to do this?
>How do I pass a date such as 08/01/2000 into the localtime function
>

I think that you are on the right track here.

The FAQ says:

  How can I compare two dates and find the difference?

    If you're storing your dates as epoch seconds then simply
    subtract one from the other. If you've got a structured date
    (distinct year, day, month, hour, minute, seconds values), then
    for reasons of accessibility, simplicity, and efficiency, merely
    use either timelocal or timegm (from the Time::Local module in
    the standard distribution) to reduce structured dates to epoch
    seconds. However, if you don't know the precise format of your
    dates, then you should probably use either of the Date::Manip
    and Date::Calc modules from CPAN before you go hacking up your
    own parsing routine to handle arbitrary date formats.

I'd also add Time::ParseDate to the list of things to consider.
It appears to be faster than the routine in Date::Manip but only
works for dates inside the unix epoch.

Good Luck
chris
-- 
    This space intentionally left blank


------------------------------

Date: 29 Nov 2000 18:09:12 +0100
From: faitsch@yahoo.com (Tim Faitsch)
Subject: Re: Dates in perl
Message-Id: <20001129170909.2291.qmail@web122.yahoomail.com>

use Date::Calc qw(Delta_Days);

__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Thousands of Stores. Millions of Products.
http://shopping.yahoo.com/

-- 
Posted from web122.mail.yahoo.com [205.180.60.57] 
via Mailgate.ORG Server - http://www.Mailgate.ORG


------------------------------

Date: Wed, 29 Nov 2000 18:50:46 GMT
From: eT <eT@quidel.com>
Subject: Extracting substrings from strings
Message-Id: <903j62$bh4$1@nnrp1.deja.com>

Hi there ... I would like to extract a substring from a string - I know
I read about this in my manual but for the life of me I can't find it!

So, if I have a string:

$a="This is a test" I want to extract eg. "is a" so that afterwards:

$a="This  test"

Thanks


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Wed, 29 Nov 2000 07:35:53 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: for each file in dir ?
Message-Id: <slrn929u19.391.tadmc@magna.metronet.com>

John W. Krahn <krahnj@acm.org> wrote:

>opendir DIR, '/path/to/dir' or die "Cannot open directory /path/to/dir:
>$!";

>while ( defined( $file = readdir DIR ) ) {
>	next if $file eq '.' or $file eq '..';
>	open FILE, "< $file" or warn "Cannot open $file: $!";
                      ^^^^^

You forgot to tack on the rest of the path (or chdir to the dir).


>	my $data;
>	read FILE, $data, -s $file;
>	print OUT $data;


You can replace the 3 lines above with this one:

   print OUT <FILE>;


But both of those approaches read the entire file into memory,
so they are Not So Good for large files.


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: Wed, 29 Nov 2000 16:53:56 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: how do i direct compiler errors to a file-newbie
Message-Id: <n2da2toll0ajlpc3m5uj5f3089o3h5k3i0@4ax.com>

Roman Stawski wrote:

>> : BEGIN {
>> :     open STDERR, ">errorlog.txt";
>> : }
>> 
>> For the -compiler- error messages?
>> 
>> Geoff
>
>You know what. It does work! Even for the -compiler- messages! Thanks Bart,
>I never would've thought of that one!

The requirement is that this BEGIN block should be in front of your
error. Perl compiles sequentially, and executes a BEGIN block as soon as
it is compiled. Yes, that does mean, before the rest of the script is
compiled.

How else would you ever expect pragma's to work? (pragma = "module" that
changes the behaviour of the compiler)

-- 
	Bart.


------------------------------

Date: 29 Nov 2000 12:22:54 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: how do i direct compiler errors to a file-newbie
Message-Id: <m31yvu7kwh.fsf@mumonkan.sunstarsys.com>

"Geoff Winkless" <geoff-at-farmline-dot-com@127.0.0.1> writes:

> "Roman Stawski" <roman.stawski@fr.adp.com> wrote in message
> news:3A251C2E.8A6FF2AC@fr.adp.com...
> : Geoff Winkless wrote:
> : >
> : > "Bart Lateur" <bart.lateur@skynet.be> wrote in message
> : > news:jcs92ts13damcgk8sp8muoujkva6hckark@4ax.com...
> : > : BEGIN {
> : > :     open STDERR, ">errorlog.txt";
> : > : }
> : > For the -compiler- error messages?
> : You know what. It does work! Even for the -compiler- messages! Thanks
> Bart,
> : I never would've thought of that one!
> 
> Ugh. That's sick. It may work but it shouldn't, the idea of a compiler
> redirecting its output based on the contents of an input file? ugh and ugh
> again.

Not sick- ingenious perhaps (as is usual from this particular poster).

% perldoc -f use

Imports some semantics into the current package from the named module,
generally by aliasing certain subroutine or variable names into your
package.  It is exactly equivalent to

    BEGIN { require Module; import Module LIST; }

except that Module I<must> be a bareword.

 ...

The C<BEGIN> forces the C<require> and C<import()> to happen at compile 
time.

 ...


If that is not specific enough, there's a full description on page 283
of the camel.  I found the online version by grepping my pod directory
tree.

% perldoc perlmod
 ...
       Package Constructors and Destructors

       There are two special subroutine definitions that function
       as package constructors and destructors.  These are the
       BEGIN and END routines.  The sub is optional for these
       routines.

       A BEGIN subroutine is executed as soon as possible, that
       is, the moment it is completely defined, even before the
       rest of the containing file is parsed.  You may have
       multiple BEGIN blocks within a file--they will execute in
       order of definition.  Because a BEGIN block executes
       immediately, it can pull in definitions of subroutines and
       such from other files in time to be visible to the rest of
       the file.  Once a BEGIN has run, it is immediately
       undefined and any code it used is returned to Perl's
       memory pool.  This means you can't ever explicitly call a
       BEGIN.
 ...


HTH
-- 
Joe Schaefer



------------------------------

Date: Wed, 29 Nov 2000 17:35:11 -0000
From: "Geoff Winkless" <geoff-at-farmline-dot-com@127.0.0.1>
Subject: Re: how do i direct compiler errors to a file-newbie
Message-Id: <903enq$ehe$1@soap.pipex.net>

"Joe Schaefer" <joe+usenet@sunstarsys.com> wrote in message
news:m31yvu7kwh.fsf@mumonkan.sunstarsys.com...
: "Geoff Winkless" <geoff-at-farmline-dot-com@127.0.0.1> writes:
: > Ugh. That's sick. It may work but it shouldn't, the idea of a compiler
: > redirecting its output based on the contents of an input file? ugh and
ugh
: > again.
:
: Not sick- ingenious perhaps (as is usual from this particular poster).

I'm happy to believe that it's a perfectly valid perl method. I'm simply
stating that I think it's sick to design a compiler which runs code while it
compiles, and actually to make use of it.

It was a comment on perl itself, rather than the suggestion.

Geoff




------------------------------

Date: Wed, 29 Nov 2000 11:21:43 -0600
From: "Neil Trenholm" <neil@alaweb.com>
Subject: How do I null terminate a string ?
Message-Id: <t2aelc77u2v3d0@corp.supernews.com>

Hi,

I don't know how I missed this in the docs ... but ... I have a string that
needs to be null terminated before being shipped off to a Win32::API

$this_string = "StringContents";

How do I do this ?

Thanks,
Neil




------------------------------

Date: Wed, 29 Nov 2000 16:18:00 GMT
From: ioa <ioa@sererico.com>
Subject: IIS CGI
Message-Id: <903a7g$35v$1@nnrp1.deja.com>

 Hi ALL!
DO I have to specify the forder where the perl is for a CGI running in
IIS.

For example:
In Unix I should say:

#!/usr/bin/perl

but # is a comment in DOS or NT ... So the system won't read that line

Thanks in advance


--
I. Suarez
Web Developer
www.quiteeasy.com
www.sererico.com


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Wed, 29 Nov 2000 07:38:41 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: lynx with PERL
Message-Id: <slrn929u6h.391.tadmc@magna.metronet.com>

waseema@my-deja.com <waseema@my-deja.com> wrote:

>open (TEMP, "/usr/bin/lynx -source '$url'|") | | die "boom...";
                                               ^
                                               ^

That space should not be there.


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: Wed, 29 Nov 2000 11:34:06 -0500
From: Bill Wang <wangbill18@hotmail.com>
Subject: one question about perl return value
Message-Id: <3A252FFE.844E14B9@hotmail.com>

This is a multi-part message in MIME format.
--------------2102C99B27BF6879706C3859
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

How to use perl to return server time, then treat the time as a start
time, so I can use javascript to display a clock.

--------------2102C99B27BF6879706C3859
Content-Type: text/x-vcard; charset=us-ascii;
 name="wangbill18.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Bill Wang
Content-Disposition: attachment;
 filename="wangbill18.vcf"

begin:vcard 
n:Hurston;Pam
tel;fax:850 644 9763
tel;work:850 644 5772
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:hurston@lis.fsu.edu
fn:Pam Hurston
end:vcard

--------------2102C99B27BF6879706C3859--



------------------------------

Date: Wed, 29 Nov 2000 17:05:10 GMT
From: simbean@my-deja.com
Subject: Re: one question about perl return value
Message-Id: <903cvu$5sp$1@nnrp1.deja.com>

??

'time' gets the current time in "seconds since 1.1.1970, 00:00:00"


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Wed, 29 Nov 2000 16:04:44 GMT
From: konstantin_wiesel@my-deja.com
Subject: Pattern matching in arrays with foreach loop
Message-Id: <9039em$2gq$1@nnrp1.deja.com>

At the end is the small routine which to my
surprise does not work as expected.
First i read the output of the tar command into
the array @directory. Now if i search two times
in the array i get different results. You can see
this in the results file which contains the
numbered lines. What am i doing wrong here?


-------------------------------------------------
#!/usr/bin/perl

my @directory;

# Archive directory reading
sub getdirectory {
    @directory = readpipe ("tar -tvzf @_");
}

sub clrscr {
    for ($i = 1; $i <= 50; $i++) {
	print "\n";
    }
}

my $kommando;
open (DATA, ">>result.txt");
do {
    print 'Your order please: ';
    $kommando = <STDIN>;
    print "Your order was $kommando";
    chop ($kommando);

    if ($kommando =~ m/[Dd]ir/) {
	print "Directory reading...";
	getdirectory('linux-2.4.0-test5.tar.gz');
    }

    if ($kommando =~ m/[Ff]ind/) {
	$name = <STDIN>;

	$j = 0;
	$k = 0;
	foreach $line (@directory) {
	    print $j++."  ".$line;
	    if ($line =~ m/rio/goi) {
		print DATA
$j."  ".$k++."  ".$line;
		}
	}
    }
} until $kommando =~ m/[Ee]nd/;
print $kommando;
close DATA;


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Wed, 29 Nov 2000 16:11:38 GMT
From: konstantin_wiesel@my-deja.com
Subject: Pattern matching in arrays with foreach loop
Message-Id: <9039rj$2oo$1@nnrp1.deja.com>



At the end is the small routine which to my surprise does not work as
expected. First i read the output of the tar command into the array
@directory. If i search this array two times consecutively i get
different results. You can see this in the results file which contains
the numbered lines. What am i doing wrong here?


-------------------------------------------------
#!/usr/bin/perl

my @directory;

# Archive directory reading
sub getdirectory {
    @directory = readpipe ("tar -tvzf @_");
}

sub clrscr {
    for ($i = 1; $i <= 50; $i++) {
	print "\n";
    }
}

my $kommando;
open (DATA, ">>result.txt");
do {
    print 'Your order please: ';
    $kommando = <STDIN>;
    print "Your order was $kommando";
    chop ($kommando);

    if ($kommando =~ m/[Dd]ir/) {
	print "Directory reading...";
	getdirectory('linux-2.4.0-test5.tar.gz');
    }

    if ($kommando =~ m/[Ff]ind/) {
	$name = <STDIN>;

	$j = 0;
	$k = 0;
	foreach $line (@directory) {
	    print $j++."  ".$line;
	    if ($line =~ m/rio/goi) {
		print DATA $j."  ".$k++."  ".$line;
		}
	}
    }
} until $kommando =~ m/[Ee]nd/;
print $kommando;
close DATA;


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Wed, 29 Nov 2000 12:58:41 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Poll it
Message-Id: <slrn92aguh.400.tadmc@magna.metronet.com>


[ Jeopardectomy performed ]


Kos <kseterba@chello.no> wrote:
>
>"Tad McClellan" <tadmc@metronet.com> wrote in message
>news:slrn9281q6.12l.tadmc@magna.metronet.com...
>> Kos <kseterba@chello.no> wrote:
>>
>> >I am using Pollit
>>
>> Send mail to jason@cgi-world.com then.
>>
>> [ snip *1100* lines of code! ]


>I did but he said that its not supported


Then you have only 3 choices, none of which is "post
a thousand lines of code to Usenet":

   1) Stop using Pollit. (recommended)

   2) Learn enough Perl to do it yourself. (errr, also recommended :-)

   3) Hire someone who already knows Perl to do it for you.


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: Wed, 29 Nov 2000 08:11:12 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Reading a csv file
Message-Id: <3A252AA0.45FA3963@vpservices.com>

Ilmari Karonen wrote:
> 
> In article <slrn928de2.br5.mgjv@verbruggen.comdyn.com.au>, Martien Verbruggen wrote:
> >
> >You can't honestly expect any CSV parser to allow invalid syntax.  CSV
> >is a defined file format. You can't just make something up that has
> >commas, call it CSV, and then expect CSV_XS to parse it.
> 
> Why not?  Just about everyone else has.
> 
> CSV files are a perfect example of the old saying about standards,
> namely that the nice thing about them is that there are so many to
> choose from.  Some formats use backslash escapes or something similar,
> most don't.  Some allow newlines in quoted strings, some require them
> to be preceded by some escape character, some want them as \n or
> something else, and some just plain forbit them.  Some allow lone
> quotes in all fields, some only in non-quoted fields, some not at all.

Which is precisely the value of something like Text::CSV_XS, since it
handles almost all of the options you mention as user-definable settings
and the options that it doesn't handle, it is specific about so that the
user is free to massage those aspect any way they want.

-- 
Jeff


------------------------------

Date: Wed, 29 Nov 2000 10:19:57 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Regex question about \x$1
Message-Id: <slrn92a7kt.3fs.tadmc@magna.metronet.com>

theredviper@my-deja.com <theredviper@my-deja.com> wrote:
>I would like thank everyone for the comments and suggestions; they are
>all appreciated.  This was part of a project that was neither work
>related nor classroom related, but only one for the sake of learning
>more about perl and regular expressions.


As the overwhelming majority of posts here _are_ for 
work, you should have said that yours was not.

If you had lurked here awhile, you would have known that
most are for "real" code.

Reading minds is a hit-or-miss thing here. You shouldn't be
surprised when "misses" happen.

You can avoid mindreading by stating what you are thinking.


>I just have a few comments about the last post.  I hope I don't step on
>anyone's toes, 


Have you lurked here a bit before posting?

That is how you avoid stepping on someone's toes in newsgroups.


>I just want to clarify a few points.
>
>Please excuse my quoting style, I'll work more on it next weekend. :)


You're doing it fine now, except you should not quote .sigs.


>In article <slrn9209bh.3oc.tadmc@magna.metronet.com>,
>  tadmc@metronet.com (Tad McClellan) wrote:
>> Martin Heinsdorf <martinheinsdorf@codesign.net> wrote:
>>
>> >You're on the right track.
>>
>> No he isn't, nor are you.
>>
>> The "right track" is using a library to decode URLs, where all
>> of the tiny details have already been worked out, and the
>> solution has been examined by many people.
>>
>
>The "right track" would certainly depend on my goals or destination
>which you were unaware of, 


Errr, you expected to get help without telling us what your
goals are?  

That seems unreasonable.

Particularly when your goals are different from the goals of
nearly all of the other posts here.


>so you don't have enough information to say
>that I'm on the wrong track.  


So you did not give enough information for someone to help
you find the right track.


>> Doing this as anything other than simply a learning exercise
>> where you will not be using the code in "real" programs
>> is the Wrong Track.
>
>right on.


But you didn't tell us that!

You seem to think that we know what you are thinking without
you saying what you are thinking.

That seems unreasonable.


>> Your "solution" isn't good enough yet either.
>>
>> (But experienced lurkers would have already distrusted your
>>  advice due to cues given by your quoting style.
>>
>>  Whether Jeopardy quoting really correlates to lower-quality
>>  content does not matter. What matters is the perception
>>  of the newsgroup readers. And that perception hereabouts
>>  is well established.
>>
>>  Don't reverse time if you don't want to be discounted.
>> )
>
>Is discrediting someone elses comment the only way people will accept
>yours?


It seems that neither one of you has lurked here for a bit
before posting, else you would already know how Jeopardy
posting is received here.

It is standard 'netiquette to lurk before posting.

So you waded into a foreign society without knowing what
is socially acceptable in that society.

You shouldn't act all surprised when you committ a faux pax,
you should be expecting that you might step on toes.



So, since neither of you appeared to know how it is received
here, I told you, so that you could fit in.

If you're walking around with toilet paper stuck to your shoe,
you should be _appreciative_ when someone points it out to you.

I told you something important that you did not know.

That is not "discrediting" nor "bad attitude".

That is being helpful.


>True. The above string would cause problems, but I'm only working with
>URL encoded data.


You never told us that either!

You seem to think that we know what you are thinking without
you saying what you are thinking.


>With all of your comments Tad


There will be no more of my comments on postings from you,
sorry to have wasted your time.


>Thanks again to everyone for all the comments.  This group is a great
>place to learn about programming perl and sadly about bad attitudes.


You don't have enough information to say anything about
the attitudes in this newsgroup because you did not lurk
before posting.

Disregarding 'netiquette is a bad attitude.


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: Wed, 29 Nov 2000 19:00:56 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Regex to zero pad an IP address
Message-Id: <t2akj8igjp25b2@corp.supernews.com>

Peter Sundstrom (peter.sundstrom@eds.com) wrote:
: I'm playing around (with not much success) with a regex to convert a
: standard IP address into a zero padded format.
: 
: Eg:
: 192.1.10.1
: becomes
: 192.001.010.001
: 
: Is a regex the best way to approach it?

I think so.  One regex way:

  $ip =~ s/(\d+)/sprintf '%03d', $1/eg;

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Here's to the struggles of the silent war,
   |   here's to the closing of the age." -The Call


------------------------------

Date: 29 Nov 2000 07:52:32 -0800
From: Petri Oksanen <Petri_member@newsguy.com>
Subject: Re: running Perl program on NT and accessing a UNIX machine
Message-Id: <9038o001ukn@edrn.newsguy.com>

In article <3A24EBAB.E1CD4FF0@patriot.net>, H says...
> Maybe I'm making this simpler than it needs to be, but why
> not use Net::Telnet?
> I use it all the time to log into my ISP...

They wouldn't happen to use NT on the servers that you telnet to, would they?
In that case, would you mind sharing your script?
Because I can't get Net::Telnet to work against Seattle Labs Telnet on NT, or
Win2000 Telnet.
The problem seems to be exactly what the author of Net::Telnet warns about in
the docs; Win32 telnet servers keep sending out escape sequences in spite of the
fact that I have turned that feature off in the server app.

It works great against telnet servers on real operating systems, but not against
Win32.
I can log in successfully on Win32, but I can't execute any commands on the
remote computer.
I have tried both cmd and waitfor/print, but neither works.

When I compare the dump_logs between successful sessions against SunOS with the
failing ones, I notice that against SunOS (vt100), Net::Telnet will nicely wait
for the remote prompt to appear before sending off my remote command.
On Win32 on the other hand, it will send off the command immediately after the
password.
The prompt appears later, together with some escape-codes, and the command, that
has obviously been buffered. I don't know if it is run, its output is not sent
via telnet anyway.

Here is my code:
---8<---
#!/usr/bin/perl -w
use strict;
use Net::Telnet ();

my $host = "myhost";
my $user = "myname";
my $passwd = "mypasswd";
my $prompt = 'X:\mydir>';

my $t = new Net::Telnet (Timeout => 20, Prompt => "/$prompt/");
print "Object created.\n";
$t->dump_log("dump.txt");
$t->input_log("input.txt");
$t->open($host);
print "Connected to '$host'.\n";
#$t->login(Name => $user, Password => $passwd, Prompt => "/$prompt/"); # Won't
work on Win32.
$t->waitfor(Match => '/log[oi]n: /', Timeout => 10); # Won't work with anchors.
$t->print($user);
$t->waitfor(Match => '/password: /', Timeout => 10); # Won't work with anchors.
$t->print($passwd);
print "Logged in.\n";
#$t->binmode(1); # Doesn't help.
#print "Translation off.\n";
my @lines = $t->cmd(String => "ver", Prompt => "/$prompt/", Timeout => 10);
#$t->waitfor(Match => "/$prompt/", Timeout => 10);
#$t->print("ver");
print "Executed command.\n";
print for (@lines);
$t->close;
---8<---

The cmd() fails with a timeout.
I would appreciate any tips on matter.


Petri Oksanen



------------------------------

Date: Wed, 29 Nov 2000 11:48:46 -0500
From: "Kris Steinwender" <k s t 3 i n w 3 @ u s v i s i 0 n . c 0 m>
Subject: Search & Replace
Message-Id: <3a25322b$1_2@goliath2.newsfeeds.com>

Hi all,

    I've been thrown into writing a little Perl.  What I need to do is read
in a text file,  and get the value of line 1.  I then
have to cross reference a dictionary file that contains mappings for that
number to another number.

    After this,  I have to truncate the IDN field to the right 5 characters.

    When all this finishes, I have to rewrite the file,  with the change
within the file.

    The incoming file looks like this:

ACT 250
JCD 00
RXN 000838-1
IDN 00002228

    And should go out like this:

ACT 11037
JCD 00
RXN 000838-1
IDN 02228

    The dictionary file looks like this (the format is:  characters 1->3 are
the lookups,  4-8 are the replacement number).

25511037 StoreA
33445102 Store B
47235026 StoreC

    Thank you all in advance, any help or insight would be greatly
appreciated.

-Kris Steinwender,  U.S. Vision
kst3inw3@usvis0n.c0m
(Replace numbers with letters to reply via e-mail)




-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


------------------------------

Date: Wed, 29 Nov 2000 17:00:53 GMT
From: simbean@my-deja.com
Subject: sockets and threads
Message-Id: <903cnv$5hf$1@nnrp1.deja.com>

Hi all,

I have the following problem and I try to keep it short:

I am creating a (few) thread(s) which is listening for a connection
over a port.
The thread is detached.
When I try to close my program, I cannot because the thread is still
listening for a connection.
And I cannot close the socket while the thread is listening.
Is there a way to "remotely" kill that thread?
Or any other ideas?

Ciao,
René.


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Wed, 29 Nov 2000 11:36:14 -0500
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Re: splitting a string into an array and preserving the "\n"
Message-Id: <upba2t8l2ka3dhjr6iq2cu4p76c2bro9vj@news.supernews.net>

tchrist@perl.com (Tom Christiansen) wrote:

} ...  There's
} no reason to kowtow to confusion by the uninformed masses.  Instead,
} inform them.  Just blindly putting up with glaring inaccuracies 
} is what gets us bacteerias and noocyular missives.  All the world
} is not Texas, you know.
} 
} "Online" hardly means "Internet".   Bah.  Teach the kiddies.

Bah, yourself.  I guess that for folks who are inflexible and rooted in the
past, English in general and computer-terminology in particular, must cause
a lot of problems because it evolves and adapts so much.  For some time
now, the *common* usage of 'online' has meant "connected to the internet" 
with more restrictive meanings [connected to a local net, or connected to a
particular server] as being context-dependent subsets --- the general
unqualified [by context or otherwise] meaning of the term has grown to
embrace the Internet [as I pointed out: look at IE, with "delete all
offline content" and other online/offline discriminations; Agent has
online/offline defaults; you can go visit "The Atlantic (magazine) Online".
And most of us dial into "Online Service Providers" and lots of us have
accounts at "America Online", ICQ finds friends who are "online", etc, etc,
etc.  But then, I guess all the folk that work at those companies all are
just "kiddies" and don't know whereof they speak...  But wait...

What's funny is that you call anyone who uses the contemporary usage of
'online' (including me) a 'kiddie' [actually, in your first post you said
"script kiddie" which has absolutely no relevance to this etymological
discussion, unless you don't really know what "script kiddie" means and so
just picked it as a good, nasty-sounding ad hominem to throw out]...  Far
be it for you to realize and comprehend that some folk may actually
understand *better* than you the various meanings and nuances of computer
jargon and that the 'kiddie' is actually *YOU*.  A bit of history and
evolution:

The term online first came into usage not in the distinction between
online/offline, but rather online versus *batch*.  I wonder if there are
many/any folk here who even know what 'batch processing' is, much less have
prepared a deck of cards for an overnight batch run...  The word changed
its meaning a bit in the 70s when workstations became available and the era
of the big-iron mainframes began to wane, and so you had the notion of
"online documentation" [as distinguished from the books on your shelf] and
other usages of 'online' more in line with what Tom would like the world to
be frozen-forever using...  Online tended to mean "currently logged into a
timesharing system" [and "going offline" was pretty much the equivalent of
"logging off" or "logging out"], and by extension 'online' things were
facilities and activities you could do "while online"...  A clear evolution
from the old mainframe online/batch terminology, clearly Tom's usage, and
it mostly made sense in a non-networked world where "your system" [the one
you logged into] kind of defined the periphery of what you could access/do
"while online".

But, mores-the-pity for Tom and other folk stuck in the second-generation
usage of the term 'online' [NB: *second* generation!],  things have shifted
again: with the general-availability of the Internet [for some of us it has
been a thiry-year trip, but for most the internet only looks like it is
about seven or eight years old] "online" has mostly taken on a new, broader
meaning. 

Indeed, we are in a transition period and both meanings have use, in
context (I doubt that the very-old usage will come into vogue (or even be
useful) again any time soon.:o)).  Overall, the most *common* usage these
days is "available via the Internet" [or with "online" meaning "connected
to the internet", both at the user end [your mail client "going online" to
pick up your email] and the server end ["online services", the
research-it's "Online dictionaries", etc]].

Of course, on this basis Tom's reply is *STILL* off the mark, since, as
I've now pointed out twice, the relevant version of perlre is not "locally
online" [sic :o)] on my system (that's how the inquiry began, right?), and
so the *ONLY* rational interpretation of online in that context is
"someplace on the Internet".  That it might be "locally online" on *YOUR*
system is hardly relevant or helpful to me.  But then, being helpful was
clearly not Tom's intent... it appears that being misguidedly and
erroneously pedantic was the goal, AFAICT.

As a side bar, another part of the evolution of meaning is that its
spelling is changing. If you look in older references [e.g., the online
(sic) Merriam-Webster dictionary] you'll see that you are advised that it
should be hyphenated, "on-line", but OTOH, actual contemporary usage of the
term hasn't hyphenated it for some time now and newer references [e.g., the
online (sic again) Random House dictionary and other technical-oriented
dictionaries] have it just as a plain word 'online'.

Now back to our regularly scheduled discussion of look-behind assertions in
this here online (sic :o) forum which I mostly participate in with an
offline (sic again..:o) news client.

  /Bernie\
-- 
Bernie Cosell                     Fantasy Farm Fibers
bernie@fantasyfarm.com            Pearisburg, VA
    -->  Too many people, too few sheep  <--          


------------------------------

Date: 29 Nov 2000 10:14:43 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: splitting a string into an array and preserving the "\n"
Message-Id: <3a253983$1@cs.colorado.edu>

In article <upba2t8l2ka3dhjr6iq2cu4p76c2bro9vj@news.supernews.net>,
Bernie Cosell  <bernie@fantasyfarm.com> wrote:
>and lots of us have accounts at "America Online", 

I rest my case.

--tom


------------------------------

Date: 29 Nov 2000 16:29:14 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: system() and backticks working intermittently on Tru64 UNIX
Message-Id: <slrn92abmp.2qh.vek@pharmnl.ohout.pharmapartners.nl>

On Tue, 28 Nov 2000 19:47:12 GMT, Dan Wilga <dwilgaREMOVE@mtholyoke.edu> wrote:

>
>We had been running Apache 1.3.9 on Linux, and one of the people here was 
>having intermittent problems with the $ENV{PATH} Apache was sending it.
>


Actualy, you realy should set $ENV{PATH} in any CGI program, as the
inherited PATH is considered tainted.  See perldoc perlsec for more details.




Villy


------------------------------

Date: Wed, 29 Nov 2000 17:26:01 GMT
From: "Jim" <jim_NOSPAM_@gosquad.com>
Subject: using Filter:: directly from perl binary
Message-Id: <J_aV5.125328$n9.2503706@news2.rdc1.on.home.com>

Hi all,

 I know this is possible, because I've seen it done, but can't figure out
how to go about it.  Basically, I want to have all my source code put
through a Filter, but from the binary itself (so I don't have to specify use
Filter::Util::Call in the source).  So, say I have a source file called
'test.pl' that's entirely uuencoded, I want the perl binary to know this and
to uudecode it accordingly before running it.  Is this possible out of the
box, or will I have to do some hacking?

Thanks,
Jim




------------------------------

Date: Wed, 29 Nov 2000 09:38:24 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: working with lists of associative arrays
Message-Id: <slrn92a570.391.tadmc@magna.metronet.com>

jim crawford <pfister_@mindspring.com> wrote:

>I'm having problems working with a list of associative arrays.

>I have functions that work with this list, but I tired of typing out
>$data[$_[0]]{"fieldname"} to access the data, and tried to create a
>temporary variable as a shortcut:
>$x=$data[$_[0]];


$x now contains a reference to a hash.

You can dereference it to get to the elements in the hash:

   $x->{fieldname}


>Now... the intention is for the right side of this assignment to
>evaluate to a hash... 


But then you will have a scalar on the LHS and a hash on the RHS.

That isn't likely to do what you want it to do.


>but perl doesn't like
>%x=%data[$_[0]];
>because I "can't use subscript on associative array dereference".


To copy the hash:

   %x =%{$data[$_[0]]};  # %{REF} derefs a ref to a hash
                         # ( where REF is replaced with something
                         #   that evaluates to a reference)

Making a copy will use a lot of resources if the hash is 
"large" though. 


>This gives me the impression that in, this expression, %data
>represents a hash named data.  


You have the correct impression.


>As in (%data)[$_[0]].  


Err, no.

That is a "list slice", something altogether different. %data
will be unrolled into a list of alternating key/value pairs.
One key or value will be selected by whatever index $_[0]
evaluates to (likely zero if $_[0] is a string (key)).


>Like % is an
>operator that binds more closely than [].
>
>Clearly the expression $data[$_[0]]{"fieldname"} isn't indexing into
>the scalar "$data", given that it works.


Right. There is no $data variable in the code you have shown.


>This gives me the impression that I really have only the vaguest idea
>what the variable prefixes represent and how they affect the code.


   perldoc perldata


>I've probably gotten this far on sheer luck and some overly-friendly
>DWIM on the part of the interpreter.


I find it disheartening that many folks never get beyond that point.

You are clever to have even recognized it :-)


>I've done some research, and I haven't been able to find a good
>explanation anywhere of what's actually going on.  

   perldoc perlreftut
   perldoc perlref
   perldoc perllol
   perldoc perldsc


>I'm afraid to look
>at the perl source.


It is a dark and scary place. Your cluefulness is showing again :-)


>Another tangible problem, possibly related for all I know, is that
>this doesn't work:
>sub sortentries #($field)
>{ @data=sort { $a{$_[0]} cmp $b{$_[0]} } @data;


@data contains references to hashes, so you are sorting a list
of references. So, in your sort block, $a/$b will be _references_.

[ @data is also a "global" variable. You should be most
  parsimonous with communicating via global variables.
  You have introduced "action at a distance" there.
  Better to pass a reference to @data as a subroutine argument.
]

You are not dereferencing $a and $b in your sort block. (In fact,
you do not even refer to $a nor $b in your sort block! You
only try to index into hashes named %a and %b).

So, dereference the references instead:

   { @data=sort { $a->{$_[0]} cmp $b->{$_[0]} } @data;


As a "style issue", using $_[0] in the subroutine body is
dangerous, due to Perl's defaulting to "pass by reference"
semantics ("reference" here is not a "Perl reference". The
term is overloaded).

If you ever end up changing $_[0] when you didn't mean to,
you will have a very hard-to-find bug (the usual argument
against "pass by reference" semantics).

It is much better to "convert" it to "pass by value" semantics
by making a copy of the args, and then only using the copies
in the subroutine body:

   sub sortentries { #($field)
      my($key) = @_;
      @data = sort { $a->{$key} cmp $b->{$key} } @data;
      ...


As an added bonus, it is easier to read and understand.


>}
>
>while this does:
>sub sortentries #($field)
>{ @data=sort { deref($a, $_[0]) cmp deref($b, $_[0]) } @data;


>I'm completely at a loss as to why.


Your first one never used the scalars $a/$b, your second one did  :-)


>Please, enlighten me!


'perlreftut' will go a long way toward that, and it is only 
about 8 "pages".


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: Wed, 29 Nov 2000 18:52:09 GMT
From: ISTERIN <isterin@hotmail.com>
Subject: XS and C++
Message-Id: <903j8l$bi1$1@nnrp1.deja.com>

Just a question, can XS be used with C++ classes?  If yes how will it
interpret the namespace?  All the docs I've read seem to point to C,
even though I did see a mension of C++ once.

Ilya Sterin


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4988
**************************************


home help back first fref pref prev next nref lref last post