[17885] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 45 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 12 00:05:48 2001

Date: Thu, 11 Jan 2001 21:05:12 -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: <979275911-v10-i45@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 11 Jan 2001     Volume: 10 Number: 45

Today's topics:
    Re: a question on scope <jhelman@wsb.com>
    Re: Clearing a hash. <joe+usenet@sunstarsys.com>
    Re: Client pull from intranet server via ISP server - H (David Efflandt)
        DBIProxy Fork mode...work on NT? <loy_x@yahoo.com>
    Re: DBIProxy Fork mode...work on NT? <loy_x@yahoo.com>
        Help: Installation Failed <qiuminh@my-deja.com>
        Help: Installation Failed <qiuminh@my-deja.com>
    Re: how to use HTML::Parser <zhenghua_li@nj.trendmicro.com>
        match from the end or match the last <johnlin@chttl.com.tw>
    Re: match from the end or match the last <wyzelli@yahoo.com>
        NET::TELNET question i.e. W2K <davidkirk@mediaone.net>
    Re: NET::TELNET question i.e. W2K <wyzelli@yahoo.com>
    Re: NET::TELNET question i.e. W2K <davidkirk@mediaone.net>
    Re: NET::TELNET question i.e. W2K <davidkirk@mediaone.net>
    Re: NET::TELNET question i.e. W2K (Damian James)
        Period problem <mrbikejoc@qwest.net>
    Re: Period problem (Damian James)
    Re: perl as a login shell <mischief@velma.motion.net>
    Re: Perl idioms for converting string into list of char (Craig Berry)
    Re: Perl idioms for converting string into list of char <uri@sysarch.com>
    Re: Perl idioms for converting string into list of char <wyzelli@yahoo.com>
    Re: reading binary files <atong@operamail.com>
    Re: Returning a filename from FILEHANDLE <dan@tuatha.sidhe.org>
    Re: setsockopt (David Efflandt)
    Re: SMTP problem. <jhelman@wsb.com>
    Re: system() method won't change directories! 2obvious@my-deja.com
    Re: Want to create class/sub-class with no package egwong@netcom.com
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 12 Jan 2001 03:23:21 GMT
From: Jeff Helman <jhelman@wsb.com>
Subject: Re: a question on scope
Message-Id: <ntts5tghcnim901o1kbeqnh6vlue95thnd@4ax.com>

On Thu, 11 Jan 2001 23:19:39 GMT, dtbaker_dejanews@my-deja.com wrote:

>I have projects in which I isolate some site-specific variable
>declarations in a script,which is then "required" in several main
>"working" scripts. My question is how to avoid compilation warnings from
>variables that may only be used once.

If you are running at least 5.6.0 (which gives you lexical warning
control), the following line in your script will silence these beasts.

no warnings 'once';

If you don't have 5.6.0, upgrade. :)  If you are waiting around for
5.6.1 because you don't like .0 releases, it should be out shortly.

Concerning how to fix this problem in perls without lexical warnings,
your solution is basically what I used to use to get around that
problem.

Hope this helps,
JH



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

Date: 11 Jan 2001 21:09:24 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Clearing a hash.
Message-Id: <m31yu9v7vv.fsf@mumonkan.sunstarsys.com>

west999@my-deja.com writes:

> I have a script that assigns a bunch of keys/values to a hash.  At some
> point in that script I would like to "clear" the hash, that is to say
> get rid of all of the keys/values.
> 
> I do not want to redeclare the hash.
> 
> So far I have tried:
> undef %hash;
  ^^^^^^^^^^^^

That better work!  You could also try

%hash = ();

if you're planning to use %hash later on.

> and
> 
> %hash = "";
> 
> Neither works, the old key/values persist.

I'd test "undef %hash" again- if you can produce a consistent
misbehavior with some code, post a code snippet together with
the perl version and OS that proves you're not crazy :)


-- 
Joe Schaefer


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

Date: Fri, 12 Jan 2001 02:26:01 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Client pull from intranet server via ISP server - HELP!
Message-Id: <slrn95sqph.k5e.efflandt@efflandt.xnet.com>

On Thu, 11 Jan 2001 21:07:52 -0000, KJ <kj@royroy.fsnet.co.uk> wrote:
>Hi perl fans,
>
>I have 3 elements...
>* an internet browser.
>* a webserver hosted by an internet service provider (IIS4.0, ActivePerl5x).
>* an intranet webserver behind a firewall. (IIS4.0, ActivePerl5x).
>
>I would like to return a web page to the internet browser from the intranet
>webserver using the ISP server as a middle-man.  How can this be achieved
>using Perl?  I have read that Perl can establish socket connections, but I
>am really lost on this.
>
>Your help is much appreciated :)

Not sure if IIS has any transparent proxy capabilities like Apache has.  
My IIS experience is limited to FP2K and FTP access to a donated host
where I don't even know if they have Perl.

The classic answer to your question is the LWP module.  Or if that is too
hard for you to install, the IO::Socket module using a variation of the
webget example in 'perldoc perlipc' is a possiblility.  But you should
probably add a Host: header to the GET request, in case you work with
virtual hosts or anything needs to redirect based on the requested
hostname.

I even have a Perl script that uses the plain old Socket module to grab
web pages (mostly to check HTTP response headers or server type).  Not
sure if there is anything different about how these modules are used in
Windows, other than possibly having to binmode filehandles for anything
that might be binary.

-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Thu, 11 Jan 2001 19:21:43 -0800
From: news <loy_x@yahoo.com>
Subject: DBIProxy Fork mode...work on NT?
Message-Id: <3A5E7847.D508ACC6@yahoo.com>

I can't get this to work... should it?



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

Date: Thu, 11 Jan 2001 19:23:10 -0800
From: news <loy_x@yahoo.com>
Subject: Re: DBIProxy Fork mode...work on NT?
Message-Id: <3A5E789E.B9A1865B@yahoo.com>

btw, I have activestate 5.6.

news wrote:

> I can't get this to work... should it?



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

Date: Fri, 12 Jan 2001 04:42:44 GMT
From: Haiyan Wang <qiuminh@my-deja.com>
Subject: Help: Installation Failed
Message-Id: <93m203$hrv$1@nnrp1.deja.com>

I download ActivePerl-5.6.0.623-MSWin32-x86-multi-thread.zip and try
to install it. It gives me an error Internal Error 2336. 5,
C:\WINNT\Installer\

The OS is Win2000 Workstation.

Thanks

QM


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 12 Jan 2001 04:44:18 GMT
From: Haiyan Wang <qiuminh@my-deja.com>
Subject: Help: Installation Failed
Message-Id: <93m231$hsj$1@nnrp1.deja.com>

I download ActivePerl-5.6.0.623-MSWin32-x86-multi-thread.zip and try
to install it. It gives me an error "Internal Error 2336. 5,
C:\WINNT\Installer\". The status shows "Status: Registering Product".

The OS is Win2000 Workstation.

Thanks

QM


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 12 Jan 2001 11:55:17 +0800
From: "james roads" <zhenghua_li@nj.trendmicro.com>
Subject: Re: how to use HTML::Parser
Message-Id: <93lv6r$eqs$1@news.cz.js.cn>

thank you all very much!

because I am a newer about OOP in perl, so I ask this newbie question.

now I have known:
if api_version = 2, we must using subclass of HTML::Parser
so we should define a package and use the statement
"@ISA=qw(HTML::Parser);", and then define the handles using sub routine.

and if define api_version => 3, we needn't using the subclass,
such as:
$p = HTML::Parser->new( api_version => 3,
                         start_h => [\&start, "tagname, attr"],
                         end_h   => [\&end,   "tagname"],
                         marked_sections => 1,
                       );


"james roads" <zhenghua_li@nj.trendmicro.com> wrote in message
news:93jt12$1gqv$1@news.cz.js.cn...
> can you tell me about how to use the modules HTML::Parser?
>
> the example:
>
> use HTML::Parser;
> $p = HTML::Parser->new;
> $p->parse_file("foo.html");
>
>
> but
> "In order to make the parser do anything interesting, you must make a
> subclass where you override one or more of the following methods as
> appropriate:
>
> $self->start($tag, $attr, $attrseq, $origtext)
> "
>
>
> and now I don't know how to define the "subclass" to get the result of
file
> parsing.
>
> can anyone help me, thank you very much.
>
>
>
>




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

Date: Fri, 12 Jan 2001 12:29:47 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: match from the end or match the last
Message-Id: <93m1c6$gcf@netnews.hinet.net>

Dear all,

In regular expression, is there a modifier or any idiomic way to
match from the end (backward)?  Let's say if the modifier is 'b', then

($_ = 'xyzxyzxyz') =~ s/y/Y/b;  print;

results in:

'xyzxyzxYz'    instead of    'xYzxyzxyz'

($_ = <<EOF) =~ s/<form.*?<\/form>//b;  print;
line1
line2
<form>in form1</form>
line3
<form>in form2</form>
line4
EOF

result is:

line1
line2
<form>in form1</form>
line3
                                 <-- the last matched is substituted
line4

Thank you.

John Lin

P.S. This question is provided by Judy <ckuo03@yahoo.com>







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

Date: Fri, 12 Jan 2001 14:17:06 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: match from the end or match the last
Message-Id: <MSv76.17$zL3.5603@vic.nntp.telstra.net>

"John Lin" <johnlin@chttl.com.tw> wrote in message
news:93m1c6$gcf@netnews.hinet.net...
> Dear all,
>
> In regular expression, is there a modifier or any idiomic way to
> match from the end (backward)?  Let's say if the modifier is 'b', then
>
> ($_ = 'xyzxyzxyz') =~ s/y/Y/b;  print;
>
> results in:
>
> 'xyzxyzxYz'    instead of    'xYzxyzxyz'
>

I don't know about idiomatic, or indeed a modifier, but this does the
trick...

($_ = 'xyzxyzxyz') =~ s/(.*)y/$1Y/; print;

Wyzelli
--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;





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

Date: Fri, 12 Jan 2001 02:26:10 GMT
From: David Kirkpatrick <davidkirk@mediaone.net>
Subject: NET::TELNET question i.e. W2K
Message-Id: <3A5E6B8D.81639DD7@mediaone.net>

Hi,
  I'm new to perl so bare with me.  Some existing code written for Unix
telents to a solaris machine ok and executes commands on that machine
etc - all OK.  On W2K the same code can't login to a W2K machine.  Do I
need a W2K module or should I keep plugging away with the parameters?
davidk
Please copy davidk@inktomi.com



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

Date: Fri, 12 Jan 2001 12:15:11 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: NET::TELNET question i.e. W2K
Message-Id: <v4u76.14$zL3.4952@vic.nntp.telstra.net>

"David Kirkpatrick" <davidkirk@mediaone.net> wrote in message
news:3A5E6B8D.81639DD7@mediaone.net...
> Hi,
>   I'm new to perl so bare with me.  Some existing code written for
Unix
> telents to a solaris machine ok and executes commands on that machine
> etc - all OK.  On W2K the same code can't login to a W2K machine.  Do
I
> need a W2K module or should I keep plugging away with the parameters?
> davidk

Can you manually telnet to the W2K box?  I don't think telnet is
installed by default on W2K.

Wyzelli
--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;




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

Date: Fri, 12 Jan 2001 02:44:14 GMT
From: David Kirkpatrick <davidkirk@mediaone.net>
Subject: Re: NET::TELNET question i.e. W2K
Message-Id: <3A5E6FC9.1BCD4CD7@mediaone.net>

Hi Wyzelli,
   Yes, I set that up after the initial failures.  I can tenet in and get
the login prompt etc and log in.
   The code I'm using is just about like the snip below (I'm home at the
moment so don't have the original).
        use Net::Telnet ();
        $t = new Net::Telnet (Timeout => 10,
                              Prompt => '/bash\$ $/');
        $t->open("sparky");
        $t->login($username, $passwd);
        @lines = $t->cmd("/usr/bin/who");
        print @lines;
--------------
From some computers I get logged in directly without a login prompt.  From
some others I get a login prompt but can log in  - manualy.  The script
works fine on unix but not W2K.
Thanks dk




Wyzelli wrote:

> "David Kirkpatrick" <davidkirk@mediaone.net> wrote in message
> news:3A5E6B8D.81639DD7@mediaone.net...
> > Hi,
> >   I'm new to perl so bare with me.  Some existing code written for
> Unix
> > telents to a solaris machine ok and executes commands on that machine
> > etc - all OK.  On W2K the same code can't login to a W2K machine.  Do
> I
> > need a W2K module or should I keep plugging away with the parameters?
> > davidk
>
> Can you manually telnet to the W2K box?  I don't think telnet is
> installed by default on W2K.
>
> Wyzelli
> --
> push@x,$_ for(a..z);push@x,' ';
> @z='092018192600131419070417261504171126070002100417'=~/(..)/g;
> foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;



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

Date: Fri, 12 Jan 2001 02:50:17 GMT
From: David Kirkpatrick <davidkirk@mediaone.net>
Subject: Re: NET::TELNET question i.e. W2K
Message-Id: <3A5E7134.EACD5A3F@mediaone.net>

Wyzelli,
    I get something like got EOF reading or waiting (I forget) for login
prompt".  It think disconnects.
davidk@inktomi.com

Wyzelli wrote:

> "David Kirkpatrick" <davidkirk@mediaone.net> wrote in message
> news:3A5E6B8D.81639DD7@mediaone.net...
> > Hi,
> >   I'm new to perl so bare with me.  Some existing code written for
> Unix
> > telents to a solaris machine ok and executes commands on that machine
> > etc - all OK.  On W2K the same code can't login to a W2K machine.  Do
> I
> > need a W2K module or should I keep plugging away with the parameters?
> > davidk
>
> Can you manually telnet to the W2K box?  I don't think telnet is
> installed by default on W2K.
>
> Wyzelli
> --
> push@x,$_ for(a..z);push@x,' ';
> @z='092018192600131419070417261504171126070002100417'=~/(..)/g;
> foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;



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

Date: 12 Jan 2001 03:02:08 GMT
From: damian@puma.qimr.edu.au (Damian James)
Subject: Re: NET::TELNET question i.e. W2K
Message-Id: <slrn95ssvd.mvl.damian@puma.qimr.edu.au>

In article <v4u76.14$zL3.4952@vic.nntp.telstra.net>, Wyzelli wrote:
>Can you manually telnet to the W2K box?  I don't think telnet is
>installed by default on W2K.

Actually, it is -- it just isn't enabled by default.

At least, I installed a small number of w2k boxes last year (yes,
it did feel like the Devil's work), and recall coming upon this
by accident. NB it is a bit different to what most people here
would think of telnet (eg, SMB authentication).

To the OP: read the w2k telnet docs. Then read them again - you
probably need to change the options under which the daemon runs.

This is OT.

Cheers,
Damian



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

Date: Thu, 11 Jan 2001 19:57:38 -0700
From: "John Bickmore" <mrbikejoc@qwest.net>
Subject: Period problem
Message-Id: <Ynu76.3487$dy.572710@news.uswest.net>

Perl interprets the period between Schema and Table2 as something other than
a period, causing a compilation error.  I have tried every way I can think
of to hack around this but to no avail.

    my $table = 'Schema.Table2';
    my $sql = "select F1 as Field1, F2 as Field2,
                     from Table1, $table";

Other attempts:

    "Schema\.Table2"
    "Schema"."\."."Table2"

and so on....

Thank you in advance,

John Bickmore
www.BicycleCam.com




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

Date: 12 Jan 2001 03:18:43 GMT
From: damian@puma.qimr.edu.au (Damian James)
Subject: Re: Period problem
Message-Id: <slrn95stuf.mvl.damian@puma.qimr.edu.au>

In article <Ynu76.3487$dy.572710@news.uswest.net>, John Bickmore wrote:
>Perl interprets the period between Schema and Table2 as something other than
>a period, causing a compilation error.  I have tried every way I can think
>of to hack around this but to no avail.
>
>    my $table = 'Schema.Table2';
>    my $sql = "select F1 as Field1, F2 as Field2,
>                     from Table1, $table";

Actually, this is not true. Have you tried 'print $sql'? I think you'll
find that your compliation error is quite unrelated to the way that perl
interprets that period.

You don't provide any information about the context in which you are
using $sql, but it looks to me like you are confusing your RDBMS, by 
providing database_name.table_name for one part of the join, and just 
table_name for the other. 

I assume you are using DBI? Have you tried:

 my $sql = "select F1 as Field1, F2 as Field2,
			from Table1, Table2";
	or	   "select F1 as Field1, F2 as Field2,
			from Schema.Table1, Schema.Table2";

Incidentally, I suggest you investigate Perl's quote-like operators 
(qw//, etc). They are just about essential for writing readable SQL 
queries via DBI. See perldoc perlop.

HTH

Cheers,
Damian


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

Date: Fri, 12 Jan 2001 02:13:42 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: perl as a login shell
Message-Id: <t5sq2m6u1r9fac@corp.supernews.com>

wroot@my-deja.com wrote:
> Hi!

Hullo.

> I'm curious:

Curious enough to create a test account and try it?

> Can one use perl as a login shell?

This is a Unix question, isn't it? You make no mention of your
platform and aska platform-dependent question. This really is
more of a platform-depdendent question than a Perl-dependent one.

On every Unix I've ever tried (Linux, NetBSD, OpenBSD, FreeBSD,
Solaris x86, Minix, AIX, BSD/386, and SCO), I believe a shell
only needs to be aware of standard input, output, and error
(if even standard error). I can assure you this is the case with
Linux and some others. Anything listed as a shell in the password
file is launched by the login process as soon as authentication
is complete. From there, what you have as an interface is that
program. You could use cat if you like.

If you used the Perl executable itself as a shell, you would
log in and see nothing, since Perl isn't an interactive
programming language. You can type code at it. It will wait for
the end of a file, which would be you logging out.

You can't include command-line options to a shell in the password
file.

You could write a simple script to accept multiline input, such as:

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

print "perlshell> ";
$code = '';
while(<>) {
    chomp;
    if($_ eq '#run') {
        eval $code;
        $code = '';
    } elsif( $_ eq '#quit') {
        exit(0);
    } else {
        $code .= $_;
    }
    print "perlshell> ";
}
#################################

If you eval an exit(), you get out of your shell, too.
Notice how I made the keywords '#run' and '#quit', which
won't mean anything to Perl anyway.

Or you could make it accept only one line worth of input:
#################################
#!/usr/bin/perl
while(<>) {
    eval $_;
}
#################################


Either of these can be exited using exit().
Remember, if you eval an exit(), you get out of your shell.
You could refuse to use exit() or could filter it out and
use die() instead. You could do lots of neat little tricks
besides that.

You must hae your script set to be readable and executable for
the world to use it as a shell.

There was some talk of a Perl-based shell some time ago. I think
it was at least a year or two ago that I last heard about it.
This wasn't a regular Perl executable, but something made into
a shell with some shell-style functionality and some Perl things
in it too. Perhaps someone knows something about that.

In the meantime, I got bored enough today and was intrigued by this
question enough that I came up with the code following my .sig
block, which is fairly simple and has slightly different semantics
about command aliasing than Bash does, but should suffice to prove
that some Perl functionality can be put into a shell, even if the
shell itself is in Perl. I put it beyond my .sig block simply
because it will display as a couple of screens full of code on
many systems, and I'm not arrogant enough to think everyone will
want to read it after my already wordy post.

The aforementioned Perl mini-shell, which I call 'pw' because it
started off as a Perl snippet Wrapper, will run small snippets of
code, test the results of them if you like, clear the code
buffer, load a file into the code buffer, do a 'cat' without an
external cat program, call another program, create aliases, delete
aliases, and call programs based on aliases, change directories,
and offers a few diagnostic messages when it messes up. I slapped
it together in half an hour, so i realize it could use some major
improvements and could make wider use of subroutines instead of
one big if/elsif/else statement in the main loop. Let's just call
it a toy that might inspire someone to do something bigger and
better.


TIA for any comments on my 'wrapper'. I don't use it as a shell
just yet, but you never know. ;)

Chris


-- 
Christopher E. Stith

Parking for people we like only. All other vehicles will be vandalized.


################ code starts here ###############################
#!/usr/bin/perl

sub do_this($) {
    my $code_ref = shift;
    my $foo =  eval ${$code_ref};
    return $foo;
}

print "pw> ";
my $code = '';
my $result = 0;
my %alias = ();

while(<>) {
    chomp;
    if( $_ eq '#run' ) {
        $result = &do_this(\$code);
    } elsif( $_ eq '#new' ) {
        $code = '';
    } elsif( $_ eq '#show' ) {
        print "-------------------- Start --------------------\n";
        print "$code";
        print "--------------------- End ---------------------\n";
    } elsif( $_ eq '#test' ) {
        print "\n\nResult: $result\n\n";
    } elsif( $_ =~ /#load\s*(.*)/ ) {
        unless( open( Fh, "$1" ) ) {
            print "\n\nError opening file $1: $!\n\n";
            next;
        }
        $code = '';
        while(<Fh>) {
            $code .= $_;
        }
        close(Fh);
    } elsif( $_ =~ /#do\s*(\w*)/ ) {
        my ($command, $args) = /#do\s*(\w*)\s*(\w*)/;
        chomp($command);

        if( exists( $alias{$command} ) ) {
            $command = $alias{$command};
        }

        if( $command eq 'cd' ) {
            chdir("$args") || print "\n\nCouldn't change directory: $!\n\n";
        } elsif( $command eq 'cat') {
            unless( open( Fh, "$args" ) ) {
                print "\n\nError opening file $args: $!\n\n";
                next;
            }
            while(<Fh>) {
                print "$_";
            }
            close(Fh);
        } else {
            print "Doing: $command $args\n";
            if( system("$command $args") ) {
                print "\n\nCan't execute $command: $!\n\n"
        my ($command, $args) = /#do\s*(\w*)\s*(\w*)/;
        chomp($command);

        if( exists( $alias{$command} ) ) {
            $command = $alias{$command};
        }

        if( $command eq 'cd' ) {
            chdir("$args") || print "\n\nCouldn't change directory: $!\n\n";
        } elsif( $command eq 'cat') {
            unless( open( Fh, "$args" ) ) {
                print "\n\nError opening file $args: $!\n\n";
                next;
            }
            while(<Fh>) {
                print "$_";
            }
            close(Fh);
        } else {
            print "Doing: $command $args\n";
            if( system("$command $args") ) {
                print "\n\nCan't execute $command: $!\n\n"
            }
        }
    } elsif( $_ =~ /#alias\s*(.*)/ ) {
        chomp($1);
        if( length($1) ) {
            my ($alias_name, $alias_action) = split(/=/, $1);
            if( length( $alias_action ) ) {
                $alias{$alias_name} = $alias_action;
                print "New alias: $alias_name\n";
                print "Action:    $alias{$alias_name}\n";
            } else {
                delete( $alias{$alias_name} );
            }
        } else {
            for( keys( %alias ) ) {
                print "$_: $alias{$_}\n";
            }
        }
    } elsif( $_ eq '#quit' ) {
        exit(0);
    } elsif( $_ =~ /#(.*)/ ) {
        my ($command, $args) = /#(\w*)\s*(\w*)/;
        chomp($command);

        if( exists( $alias{$command} ) ) {
            $command = $alias{$command};
        }
        print "Doing: $command $args\n";
        if( system("$command $args") ) {
            print "\n\nCan't execute $command: $!\n\n"
        }
    } else {
        $code .= "$_\n";
    }
    print "pw> ";
}

######################### end of code #############################


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

Date: Fri, 12 Jan 2001 02:12:35 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Perl idioms for converting string into list of characters...
Message-Id: <t5sq0jmp4tae85@corp.supernews.com>

Weston Cann (iowa88_song88.remove_eights@hotmail.com) wrote:
: I can figure out a way convert a string into a list of characters via
: repeated use of the substr function. 
: It also looks as if you can do it using split(//,$str). 

The latter is the prefered idiom.

: Are there other perl idioms for doing this?

@chars = $str =~ m/./gs;

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "The hills are burning, and the wind is raging; and the clock
   |   strikes midnight in the Garden of Allah." - Don Henley


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

Date: Fri, 12 Jan 2001 03:41:47 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Perl idioms for converting string into list of characters...
Message-Id: <x7ofxd3090.fsf@home.sysarch.com>

>>>>> "W" == Wyzelli  <wyzelli@yahoo.com> writes:

  W> "Weston Cann" <iowa88_song88.remove_eights@hotmail.com> wrote in message
  W> news:iowa88_song88.remove_eights-1101011149120001@58.salt-lake-city-03-0
  W> 4rs.ut.dial-access.att.net...
  >> I can figure out a way convert a string into a list of characters via
  >> repeated use of the substr function.
  >> 
  >> It also looks as if you can do it using split(//,$str).
  >> 
  >> Are there other perl idioms for doing this?
  >> 

  W> @chars = split /|/,$string;

i hope you are being silly, since that is just two null strings and
since a null string always matches (the char pointer gets bumped after
each match), the second one never gets used and it reduces the OP's
split.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Fri, 12 Jan 2001 13:59:48 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Perl idioms for converting string into list of characters...
Message-Id: <pDv76.16$zL3.5097@vic.nntp.telstra.net>

"Uri Guttman" <uri@sysarch.com> wrote in message
news:x7ofxd3090.fsf@home.sysarch.com...
> >>>>> "W" == Wyzelli  <wyzelli@yahoo.com> writes:
>
>
>   W> @chars = split /|/,$string;
>
> i hope you are being silly, since that is just two null strings and
> since a null string always matches (the char pointer gets bumped after
> each match), the second one never gets used and it reduces the OP's
> split.
>

Sometimes I just get these moods you know? :)

Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_!=1)? 's':'';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';





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

Date: Fri, 12 Jan 2001 10:11:22 +0800
From: "Meow" <atong@operamail.com>
Subject: Re: reading binary files
Message-Id: <93lp4e$243@news.or.intel.com>

s/\cM//g;
this will solve your issue..

rgds,
meow.......

<littlesputnik@my-deja.com> wrote in message
news:93li9k$4mu$1@nnrp1.deja.com...
> Hello,
>
> I am trying to use a perl script to strip "^M" characters from a file,
> but they are transparent to the perl interpreter.  Is there some other
> way to specify "^M" so that the perl interpreter will see it and
>
> $line=~s/^M//;
>
> will work?
> Thanks.
>
> Heather
>
>
> Sent via Deja.com
> http://www.deja.com/




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

Date: Fri, 12 Jan 2001 04:36:02 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: Returning a filename from FILEHANDLE
Message-Id: <SQv76.133040$P82.15905338@news1.rdc1.ct.home.com>

Julian Cook/Sherab Gyatso <president@webticker.com> wrote:
> I found the answer thanks to Deja.com. For anyone else using deja who may
> have this same
> question.....
> The answer is no.

Actually, the answer is "it depends on your platform". Some can, some can't.
VMS can, and I think if you're really clever with XS code you can get the
info out of at least some of the unices.

>> Hi folks!
>> My thanks in advance to all who make this a great place to
>> be. I have certainly gotten more than my fair share of free advice.
>>
>> Is there a function is PERL  that will return what a filehandle is
>> associated with?
>>
>> Where <FILES> refers to "files.txt" Could I somehow ask <FILES>
>> to give me what it's reading?
>>
>> Many thanks again.
>> --
>> Julian Cook
>> President
>> WebTicker News Syndicate
>> president@webticker.com
>> ----------------------------------------------------------------------
>> 7,000,000 monthly news deliveries, a network of 20,000 sites,
>> 16 channels of information, one news leader,assisting numerous
>> charities...WebTicker News Syndicate
>> http://www.webticker.com
>> ----------------------------------------------------------------------

> --
> Julian Cook
> President
> WebTicker News Syndicate
> president@webticker.com
> 202-761-0036 - Capitol Hill Office
> ----------------------------------------------------------------------
> 6,000,000 monthly news deliveries, a network of 16,000 sites,
> 16 channels of information, one news leader,assisting numerous
> charities...WebTicker News Syndicate
> http://www.webticker.com
> ----------------------------------------------------------------------




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

Date: Fri, 12 Jan 2001 02:40:11 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: setsockopt
Message-Id: <slrn95srk4.k5e.efflandt@efflandt.xnet.com>

On 11 Jan 01 20:30:36 GMT, Paul Falbe <paul@cassens.com> wrote:
>I am wanting to to send some information via a socket using Perl.  However
>I am wanting to interface eth1 under linux.  I know in C you would
>use the setsockopt function.  I know Perl has this function also.  In looking
>through the manual I see little documentation.  Has anyone there done this?

In your shell type:

perldoc Socket
perldoc perlipc

-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Fri, 12 Jan 2001 03:49:36 GMT
From: Jeff Helman <jhelman@wsb.com>
Subject: Re: SMTP problem.
Message-Id: <a8vs5to4anetoqt969a53qlbvmeog60ql8@4ax.com>

On Thu, 11 Jan 2001 08:57:30 -0800, "Navarone Webmaster"
<webmaster@navarone.com> wrote:

>Initially, I had problems communicating with the mail server because I was
>ending the commands (HELO, MAIL, etc.) with only a '\n' instead of a '\r\n'.
>I am now also including the '\r\n' in the body as necessary, but still no
>go. Here is a portion of the code in question...

{SNIP}

Have you tried one of the various pre-coded SMTP modules available?
Not only will they save you the trouble of dealing with the low-level
socket stuff, but they have been rigorously debugged.  Two that spring
to mind are MIME::Lite from CPAN (which frees you from the SMTP stuff
and will also handle attachments for you...tres cool), or, if you
really want to diddle with SMTP, use the Net::SMTP module (also from
CPAN, though ActivePerl from Activestate includes it with their
distribution).

In short, if you construct a script using one of these beasts and your
problem persists, the problem is with your mail server (probably
configuration), and you should seek advice in the proper forum.  If
the problem disappears, then the bug was in your code and you should
take away the lesson (as all of us have at some point in the past,
generally to our chagrin) that using existing, tested code is probably
better than rolling your own.

Hope this helps,
JH



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

Date: Fri, 12 Jan 2001 02:21:10 GMT
From: 2obvious@my-deja.com
Subject: Re: system() method won't change directories!
Message-Id: <93lpmf$b1k$1@nnrp1.deja.com>

In article <3a5d0d94$1@news.microsoft.com>,
  "Jürgen Exner" <juex@deja.com> wrote:
> <2obvious@my-deja.com> wrote in message news:93is6t$pi3
$1@nnrp1.deja.com...
> > Um, permit me to revise my original question.  What I'm ACTUALLY
trying
> > to do is execute another application (that's why I want to go the
> > c:\Program Files directory).  The app takes command line
arguments.  If
> > I were running this app from the command line, I would do something
> > like this:
> >
> > cd "c:\Program Files\Application"
> > Application /file="c:\WINDOWS\Desktop\File.txt"
> [...]
> > So what can I do?  Is there a way to invoke more than one line in a
> > system() call?  Any different/better suggestions?  Please help me
out.
>
> Have you tried to write both commands into one line?
>     system 'cd "c:/Program Files/Application" & Application
> /file="c:/WINDOWS/Desktop/File.txt"'
> Of course this is not portable but probably that is the least of your
> worries right now.
>
> On the other hand: why do you need to cd to the Application folder in
the
> first place?

Uh, because I'm an inept command line programmer? \:-S

> Can't you simply use an absolute path to call the application:
>     system 'c:/Program Files/Application/Application
> /file="c:\WINDOWS\Desktop\File.txt"'
>
> jue

Yes, I can, and thanks to you, I have.  Unfortunately, I can't insert a
scalar in the middle of the command line.  But now my script does work
(which is more than it did before), and beggars can't choose.

Everyone in this newsgroup who helped me, a thousand thanks!

--E.


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 12 Jan 2001 04:55:37 GMT
From: egwong@netcom.com
Subject: Re: Want to create class/sub-class with no package
Message-Id: <d7w76.2964$J%.294402@news.flash.net>


> While each of your classes need to be in its own class, they needn't
> be in different files.  For example

should read
	While each of your classes need to be in its own package,
	they needn't be in different files.	For example  ^^^^^^^

*sigh*


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

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 V10 Issue 45
*************************************


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