[11863] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5463 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 23 11:07:32 1999

Date: Fri, 23 Apr 99 08:00:21 -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           Fri, 23 Apr 1999     Volume: 8 Number: 5463

Today's topics:
        $ENV <jamesthurley@hotmail.com>
    Re: $ENV <gellyfish@gellyfish.com>
    Re: $ENV (Larry Rosler)
        Calling sub from generated html page <hvermeulen@correctnl.com>
    Re: Changing multiple lines in a file <mylist@zaz.com.br>
    Re: combining multiple grep statements into one... (markus)
    Re: combining multiple grep statements into one... (Bart Lateur)
    Re: Database file locking... (Steve van der Burg)
        delete() with MLDBM <tpost@intelihealth.com>
    Re: delete() with MLDBM <tpost@intelihealth.com>
    Re: Evaluating User Input (markus)
    Re: Evaluating User Input (Bart Lateur)
    Re: how to merge? (markus)
        I need help with pipes in perl! <amoral@netmode.ntua.gr>
        I need help!!!!! <sergue@ica.net>
    Re: I need help!!!!! <eyounes@aol.com>
    Re: Illegal seek (this makes no sense to me =) (Tad McClellan)
    Re: Is there a shorter way? (Abigail)
    Re: newbie with a "howto" question <bradw@newbridge.com>
    Re: newbie with a "howto" question (Abigail)
    Re: printf problem <Michael.Cameron@nospam.technologist.com>
    Re: regex: I see THAT it works, but I don't see WHY <dgris@moiraine.dimensional.com>
    Re: regex: I see THAT it works, but I don't see WHY (Tad McClellan)
    Re: regex: I see THAT it works, but I don't see WHY <uri@sysarch.com>
    Re: Sending binary values? (Neil Cherry)
    Re: Telnet problems scott@sboss.net
    Re: where is perlcore.dll? <c4jgurney@my-dejanews.com>
    Re: where is perlcore.dll? <ibelgaufts@gfc-net.de>
    Re: yet another Abigail sig (Benjamin Franz)
    Re: yet another Abigail sig (Abigail)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Fri, 23 Apr 1999 12:44:25 +0100
From: "James Thurley" <jamesthurley@hotmail.com>
Subject: $ENV
Message-Id: <7fpml7$tsk$1@panther.rmplc.co.uk>

Where can I find info on the structure of the $ENV variable.

Chees,
James.




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

Date: 23 Apr 1999 15:10:57 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: $ENV
Message-Id: <37207f71@newsread3.dircon.co.uk>

James Thurley <jamesthurley@hotmail.com> wrote:
> Where can I find info on the structure of the $ENV variable.
> 

You can find out about this from the perlvar manpage.  It is infact a hash
%ENV that is keyed on the name of the environment variable - try this:

while (($key,$value) = each %ENV )
{
   print "$key = $value\n";
}

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>



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

Date: Fri, 23 Apr 1999 07:09:54 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: $ENV
Message-Id: <MPG.118a1f0c32b5b5fe98991e@nntp.hpl.hp.com>

[Posted and a courtesy copy sent.]

In article <7fpml7$tsk$1@panther.rmplc.co.uk> on Fri, 23 Apr 1999 
12:44:25 +0100, James Thurley <jamesthurley@hotmail.com> says...
> Where can I find info on the structure of the $ENV variable.

There is no $ENV variable (assuming you mean a Perl-defined special 
variable).  There is a hash %ENV, which you can read about in the 
document named 'perlvar'.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 23 Apr 1999 12:47:39 GMT
From: Henry Vermeulen <hvermeulen@correctnl.com>
Subject: Calling sub from generated html page
Message-Id: <37206B67.1B42A853@correctnl.com>

Hi all.
I have the following problem.
I wrote a cgi script that, while running, creates a html form in the
browser when a certain filename exist.
Th user has tree actions to choose from.
Each button has to call a subroutine in the running script but i can't
get it working this way.
Calling the sub from inside the script all goes well.
Below the generated form.
Has anyone a hint or who knows which manpage/faq contains information
about it.

Thanx
Henry Vermeulen

print "<html><head></head><body bgcolor=#FFFFFF>\n";
 print "File already exist!\n<p>";
 print "<form name=checkit action=/cgi-bin/verz_bil.cgi&checkit><br>";
 print "<input type=submit value=Replace>";
 print "<input type=submit value=View>";
 print "<input type=submit value=Back><br>";
 print "</body></html>";



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

Date: Fri, 23 Apr 1999 08:10:32 -0300
From: "Alexandre E. Knorst" <mylist@zaz.com.br>
Subject: Re: Changing multiple lines in a file
Message-Id: <7fpq13$l5u$2@srv4-poa.nutecnet.com.br>

with vi
:%s/old text/new text/g


John Wilkinson escreveu na mensagem
<3720205F.B23F8F6B@soton.sc.philips.com>...
>Hi all,
>I am a newie to this perl stuff, so excuse my ignorance.
>I have a file that will need to have several lines of text changed.
>I have saved the changes in a seperate file as
>>as I have done in the past when I wrote this as a SED script.
>I was under the impression that I could use this file and, after reading
>
>in the file to change, operate on it with this other file  somehow.
>But I cant figure out how.
>
>I am sure there must be a better way in perl, could someone help me
>please.
>
>Thanks,
>John.
>
>
>




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

Date: 21 Apr 1999 19:50:28 GMT
From: drbrain@ziemlich.org (markus)
Subject: Re: combining multiple grep statements into one...
Message-Id: <slrn7hsb04.mh3.drbrain@josefine.ben.tuwien.ac.at>

In article <7fl99n$8u7$1@shell18.ba.best.com>, Jim Matzdorff wrote:
>I am wondering if there's a neat perl trick to combine multiple perl
>grep statements into one.  For instance, currently I have the following
>lines:
>

try:

@found = grep( /(Pattern1|PAttern2)/, @data);

sincerly,
	markus


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

Date: Fri, 23 Apr 1999 13:25:31 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: combining multiple grep statements into one...
Message-Id: <372473f7.24659457@news.skynet.be>

Jim Matzdorff wrote:

>my ($search) = qq /'1.$count'/;
>my (@ret_lines) = grep /$search/, @lines;  
>@ret_lines = grep /Search_Param/, @ret_lines;
>if (@ret_lines && (my ($found) = grep /OK/, @ret_lines))
>{
>	print "Line is $found\n";
>}
>
>is there some way I can just do a:
>
>if (my ($found) == grep /<$search,Search_Param,OK>/, @lines)
>{
>	print "Line is $found\n";
>}

Do you mean this is supposed to do the same as:

my ($found) = grep { /OK/ } grep { /Search_Param/ } grep { /$search/ }
	@lines;  

I cetrainly looks that way. Uhuh. That's an AND. So:

my ($found) = grep { /Search_Param/ && /$search/ && /OK/ } @lines;

	Bart.


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

Date: Fri, 23 Apr 1999 14:11:12 GMT
From: steve.vanderburg@lhsc.on.ca (Steve van der Burg)
Subject: Re: Database file locking...
Message-Id: <7fpup1$18p@falcon.ccs.uwo.ca>

> In comp.lang.perl.misc, "Doug Crabtree" <Not@gonna.tell> writes:
> :My question is, using MLDBM, do I have to worry about two users on a
> :web site reading/writing from this file at the same time?

One way to do it would be to back MLDBM with GDBM.  GDBM does its own file 
locking.  The only trick to making the MLDBM/GDBM combination useful is to 
code for a failure to get a read or write lock by (possibly) sleeping for a 
short time and trying again.

As someone who uses this very combination, here's a "wait to tie" routine that 
I use, wrapped in a module (I'll make an installable tarball of the module 
available if anyone wants it).

----- begin module code -----

package MLtie;

# MLtie.pm -- try to tie to an MLDBM (backed by GDBM) database until
#             timed out.
#

use GDBM_File;
use MLDBM qw(GDBM_File Storable);
use strict;

require 5.004;
require Exporter;

use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK);

@ISA = qw(Exporter);
@EXPORT = qw();
@EXPORT_OK = qw(tie_mldbm);

$VERSION = '0.01';

sub tie_mldbm {
   my ($gdbm_db,$hashref,$tiefunc,$time_to_try) = @_;
   my $i = 0;
   my $db_mode;
   my $tres;

   $db_mode = ($tiefunc eq 'read') ? GDBM_READER : GDBM_WRCREAT;

   $time_to_try = 0 if $time_to_try < 0;

   while ($i < $time_to_try) {
      tie (%$hashref, 'MLDBM', $gdbm_db, $db_mode, 0640);
      $tres = tied(%$hashref);

      if ( defined($tres) ) { last;    }
      else                  { sleep 1; }
      $i++;
   }

   if ( defined($tres) ) {
      undef $tres;
      return 1;
   }
   else {
      return;
   }
};

1;
__END__

=head1 NAME

MLtie - try to tie to an MLDBM (backed by GDBM) database until timed out.

=head1 SYNOPSIS

 use MLtie;

=head1 DESCRIPTION

Module contains a timed tie for MLDBM backed by GDBM_File.

=head1 FUNCTIONS

=over 5

=item tie_mldbm( $database, $hashref, $tiefunc, $time_to_try )

Tries for $time_to_try seconds to tie the (possibly multi-level) hash 
referenced in $hashref using $tiefunc ('read' or 'write').

Returns true (1) if the tie worked, and undef if it didn't.

Example:

=over 10

use MLtie qw/tie_mldbm/;

my $mydb = "/some/data/base.gdbm";

my %MYHASH;

die unless tie_mldbm( $mydb,\%MYHASH,'read',5 );

# do something with the tied data here...

=back

=head1 NOTES

This little piece of code may be freely used, abused, rearranged, added to, 
subtracted from, and otherwise manipulated by anyone, anywhere, at any time.

=head1 AUTHOR

Steve van der Burg <steve.vanderburg@lhsc.on.ca>

=cut

----- end module code -----

 ..Steve
--


--
Steve van der Burg
Technical Analyst, Information Services
London Health Sciences Centre
London, Ontario, Canada
Email: steve.vanderburg@lhsc.on.ca


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

Date: Fri, 23 Apr 1999 08:00:58 -0400
From: Tony Demark <tpost@intelihealth.com>
Subject: delete() with MLDBM
Message-Id: <372060F5.D759F779@intelihealth.com>

I have an MLDBM db that is a hash of hashes.  Access to the hashes is
achieved by:

my %db;
tie %db, 'MLDBM'....

my $tmp = $db{key1}
my $x = $tmp->{key2}

But how does one delete from the DB?

delete($tmp->{key2}) doesn't work for me.

Thanks,
- Tony




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

Date: Fri, 23 Apr 1999 08:24:19 -0400
From: Tony Demark <tpost@intelihealth.com>
Subject: Re: delete() with MLDBM
Message-Id: <3720666C.57B7F08E@intelihealth.com>

OK... it was a case of me not seeing the forest for the trees.

After you delete(), assign $tmp back to the $db{key}.

So:

my $tmp = $db{key1}
delete($tmp->{key2})
$db{key1} = $tmp

(Yes, I know its in the docs, but I was so intent on finding a 'delete'
method, I didn't occur to me that deleting  would fall under the
"modify" domain).

Sorry to waste bandwith,
- Tony

Tony Demark wrote:

> I have an MLDBM db that is a hash of hashes.  Access to the hashes is
> achieved by:
>
> my %db;
> tie %db, 'MLDBM'....
>
> my $tmp = $db{key1}
> my $x = $tmp->{key2}
>
> But how does one delete from the DB?
>
> delete($tmp->{key2}) doesn't work for me.
>
> Thanks,
> - Tony



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

Date: 21 Apr 1999 19:32:21 GMT
From: drbrain@ziemlich.org (markus)
Subject: Re: Evaluating User Input
Message-Id: <slrn7hs9u5.mda.drbrain@josefine.ben.tuwien.ac.at>

In article <ban.1-2104991528340001@mansb195.mansfield.ohio-state.edu>,
Chunsheng Ban wrote:
>I would like to write a program to accept user input that is
>an arithmetic expression and the program evaluate it and print
>out the result. Here is an example what I want though it does
>not work.
>

Try it with eval :

#!/usr/bin/perl
print "Enter an expression to evaluate: ";
my $userinput;
chop($userinput = <STDIN>);
$output = eval $userinput;
print "The result is ",$output,".\n";


But PLEASE NOTE that this is VERY INSECURE and using
this for cgi's is NOT RECOMMENDED.
Just try `id` as input.

sincerly,
	markus


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

Date: Fri, 23 Apr 1999 14:14:39 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Evaluating User Input
Message-Id: <37257cb3.26560466@news.skynet.be>

Chunsheng Ban wrote:

>I would like to write a program to accept user input that is
>an arithmetic expression and the program evaluate it and print
>out the result. Here is an example what I want though it does
>not work.

Do you mind if it doesn't use "eval"? :-)

Here's a simple expression evaluator. It works with + - * / % (modulus)
but not with exponentiation (because of left-to-right evaluation), is
aware of basic precedence rules, and allows parentheses for nesting.

The number formatting allowed isn't the most general either: a number
may have an optional "-", next there MUST be at least one digit,
optionally followed with a decimal point plus any number of digits (or
none).

It's a quick hack, I'm not 100% sure it works properly, but at least for
"150+-7*5" it replies "115", and for "7/3*6" it says "14". Which look
alright.

#! perl -w
 while(do{print STDERR "Enter an expression: "; defined($_=<STDIN>)}){
    chomp;
    my $result = expression();
    if(defined $result && !length) {
        print "$result \n";
    } else {
        print "Error at >$_\n";
    }
 }

 # EXPR -> EXPR + TERM
 # EXPR -> EXPR - TERM
 # EXPR -> TERM
 # TERM -> TERM * FACTOR
 # TERM -> TERM / FACTOR
 # TERM -> TERM % FACTOR
 # TERM -> FACTOR
 # FACTOR -> NUMBER
 # FACTOR -> ( EXPRESSION )

 sub expression {
    my $value = term();
    defined($value) or return;
    while(s/^([\+\-])//) {
        my $rhs = term();
        defined($rhs) or return;
        $value += $rhs if $1 eq '+';
        $value -= $rhs if $1 eq '-';
    }
    return $value;
 }

 sub term {
    my $value = factor();
    defined($value) or return;
    while(s/^([\*\/%])//) {
        my $rhs = factor();
        defined($rhs) or return;
        $value *= $rhs if $1 eq '*';
        $value /= $rhs if $1 eq '/';
        $value %= $rhs if $1 eq '%';
    }
    return $value;
 }

 sub factor {
    if (s/^\(//) {
        my $value = expression();
        defined($value) or return;
        s/^\)// or return;
        return $value;
    } elsif (s/^(-?\d+\.?\d*)//) {
        return $1+0;
    }
    return;
 }
__END__

	Bart.


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

Date: 21 Apr 1999 19:56:42 GMT
From: drbrain@ziemlich.org (markus)
Subject: Re: how to merge?
Message-Id: <slrn7hsbbq.mk1.drbrain@josefine.ben.tuwien.ac.at>

In article <7fl9gq$lt6$1@nnrp1.dejanews.com>, bing-du@tamu.edu wrote:
>I know how to use 'split' to cut a string.  How to merge all the elements (but
>seperated by space) of a list?

$merged = join ' ', @list;
                ^
				|
				+-- seperator

sincerly,
	markus


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

Date: Fri, 23 Apr 1999 17:37:37 +0300
From: Moralis Athanasios <amoral@netmode.ntua.gr>
Subject: I need help with pipes in perl!
Message-Id: <372085B0.73643FB0@netmode.ntua.gr>

I have written this script :

#!/usr/local/bin/perl -w
$| = 1;
open T, "prog |" || die;
select(STDOUT);
$| = 1;
while (<T>)
 {
        @fields=split(/ /,$_);
        print "$fields[0] $fields[1]\n";
 }
close T;

However, the result of the script seems to be buffered. It appears in
pages, as if it is waiting for some amount of data to be collected. When
this amount is collected it is printed immediately in the STDOUT, then i
halts printing until another amount of data is collected.

Does anyone know how I can overcome this problem and have unbuffered
printing?

Thanks in advance



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

Date: Fri, 23 Apr 1999 09:24:48 -0700
From: serguei <sergue@ica.net>
Subject: I need help!!!!!
Message-Id: <37209ED0.EE1C91C1@ica.net>

Can somebody help me with this task.
The point is I cant launch the script show.pl with the link <a
href=/cgi-bin/com/show.pl?index=12345>"

Whats wrong with the script show.pl

Thanks in advance

Serguei

Fragment of search.pl
******************************************************************
sub print_record {
       print "<br>\n";
       print "<a href=/cgi-bin/com/show.pl?index=12345>" . $one . "</a>
: $two</b><br>\n";
}


*************************************************
script show.pl

#!/usr/bin/perl5

use CGI;
$q = new GCI;
$index = $q->param('index');
$filename = "/web/visualweb/html/datas/data2.txt";

print "Content-type:text/html\n\n";
print <<HTMLHead;
<html><head></title>Catalog page</title></head>
<body>
HTMLHead
;

open(DATA, $filename) || die "I can't open this file: $!\n";
@indata = <DATA>;

      foreach $i(@indata){
         chop ($i);
  ($num,$one,$two,$line1,$line2,$line3,$three,$four,$five,$six,$seven,)
= split(/\|/,$i);
           @ser =
($num,$one,$two,$line1,$line2,$line3,$three,$four,$five,$six,$seven,);
         $reg = shift @ser;
               if ($reg == $index){
      print "$i.\n";

 }

}
print "</body>";
print "</html>";
close (DATA);





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

Date: Fri, 23 Apr 1999 15:41:53 +0200
From: "Ysteric's" <eyounes@aol.com>
Subject: Re: I need help!!!!!
Message-Id: <7fpsvd$irk@news.vtcom.fr>


>   @ser =
($num,$one,$two,$line1,$line2,$line3,$three,$four,$five,$six,$seven,);


i think that :
undef @ser
push @ser,
[$num,$one,$two,$line1,$line2,$line3,$three,$four,$five,$six,$seven];

is better.

Eric




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

Date: Thu, 22 Apr 1999 19:12:15 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Illegal seek (this makes no sense to me =)
Message-Id: <fcaof7.ba8.ln@magna.metronet.com>

phukit@enteract.com wrote:
: Attitude aside, thank you. =)  This helped me get the right answer.  I was
: looking in the camel book, but I evidently glossed over the relevant part.
          ^^^^^^^^^^^^^^^^^
          ^^^^^^^^^^^^^^^^^

   I think the point was that that is *not* the right place to look.

   Books have several deficiencies:

      1) they go out of date quickly

      2) you are at the mercy of the indexer

      3) they cost money


: Eric The Read <emschwar@rmi.net> wrote:
: > But that's the wrong place to look.  Haven't you read the documentation
                                                              ^^^^^^^^^^^^^
: > that comes with perl?
         ^^^^^^^^^^^^^^^

   That has none of a book's problems...


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


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

Date: 23 Apr 1999 14:39:23 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Is there a shorter way?
Message-Id: <7fq0mr$esr$2@client2.news.psi.net>

Clinton Pierce (cpierce1@ford.com) wrote on MMLX September MCMXCIII in
<URL:news:372a3131.1901559117@news.ford.com>:
\\ [poster cc'd in e-mail]
\\ 
\\ On Thu, 22 Apr 1999 09:22:23 GMT, pingouino@my-dejanews.com wrote:
\\ >Some friends of mine at work accidentally got into a little "challenge";
\\ >we implemented the same piece of code in different ways, then started
\\ >seeing who could do it in fewest characters. The task was to print out
\\ >an environment variable (in this case, USER) padded out to a minimum of
\\ >six characters with "x", or not modified if it was six characters or more.
\\ >
\\ >So, "foo" becomes "fooxxx", "foos" becomes "foosxx", "foobar" remains
\\ >"foobar" and "foobars" remains "foobars" (note how the 7-letter word is
\\ >not truncated).
\\ >
\\ >The best we came up with (with all unnnecessary spaces removed) was:
\\ >
\\ >perl -e'$_=$ENV{USER};print$_."x"x(6-split//)'

    perl -e'print"$ENV{USER}xxxxxx"=~/(.{6})/'



Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
 .qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
 .qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'


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

Date: 23 Apr 1999 07:51:05 -0400
From: bj <bradw@newbridge.com>
Subject: Re: newbie with a "howto" question
Message-Id: <op1emlbo8ra.fsf@newbridge.com>

> derose@my-dejanews.com writes:
> > I'm new at Perl, and don't really have the patience's to find the answers in
> > my books, so I thought I would ask some experts.

Do only I find it fascinating that a fairly trivial question, posted
with much attitude, gets a bunch of serious, and insightful
answers... along with some chiding, whereas the same type of question
posted sans attitude pretty much gets a rtfm or faq response? 

bj


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

Date: 23 Apr 1999 14:55:15 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: newbie with a "howto" question
Message-Id: <7fq1kj$esr$3@client2.news.psi.net>

derose@my-dejanews.com (derose@my-dejanews.com) wrote on MMLX September
MCMXCIII in <URL:news:7fnfbl$jpj$1@nnrp1.dejanews.com>:
\\ Hello,
\\ 
\\ I'm new at Perl, and don't really have the patience's to find the answers in
\\ my books, so I thought I would ask some experts.


I'd gladly come over. $125/hour plus expenses. Minimum 3 days.

\\ I have two questions really
\\ 1. Is there a comparable command or module to unix's uniq?  I want to sort and
\\ uniq a simple text file.  I've figured out how to sort it in Perl, but not how
\\ to uniq it.  If I were to do this in shell I would say something like:
\\ cat $file1 | sort | uniq > $outfile

Then do it in the shell!

\\ 2. Is there a module or function that will parse a line in a text file?  I
\\ have a file with four individual columns, and I want to read each line on at
\\ a time and have each word placed in an individual variable.  If I were to do
\\ this in shell, I would have used awk to parse the lines.

And that's how people do it in Perl as well. They call awk from Perl.

\\ If any one could point me in the correct direction, I would appreciate it.


I'd go to the left, and then continue. Once you reach the icy place with
the penguins, ask again.



Abigail
-- 
perl -wlpe '}{$_=$.' file  # Count the number of lines.


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

Date: Fri, 23 Apr 1999 13:30:35 +0000
From: Michael Cameron <Michael.Cameron@nospam.technologist.com>
To: Mika Lehto <mika.lehto@comptel.com>
Subject: Re: printf problem
Message-Id: <372075FB.DFA11EFD@nospam.technologist.com>

Mika Lehto wrote:

> printf("$string_format", $string_values) does not work.

Yes it does work.  It does not do what you want it to.

printf($string_format, $values[0], $values[1], $values[2]);

Is probably nearing to what you were aiming for.

First stop:       perfdoc -f printf

HTH,

Michael



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

Date: 23 Apr 1999 07:13:00 -0600
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: regex: I see THAT it works, but I don't see WHY
Message-Id: <m3emlb8opv.fsf@moiraine.dimensional.com>

Uri Guttman <uri@sysarch.com> writes:

> >>>>> "DG" == Daniel Grisinger <dgris@moiraine.dimensional.com> writes:
> 
>   DG> Uri Guttman <uri@sysarch.com> writes:
>   >> you are confusing 2 different uses of ? in regexes (and there is a
                                     ^^^^
>   DG> 1- The simple ?
>   DG>      /\?/;                    # just a ?
> 
> not a regex metachar.

Hey, who was specifying that it had to be a metachar?  Not you.
You said 3 different `uses'. :-)

>   DG> 5- The lazy ?
>   DG>      ?.? ;                    # i'm done for the day
> 
> who really uses this (it is also deprecated)? 

I do.

dgris
-- 
Daniel Grisinger          dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print 
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'


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

Date: Fri, 23 Apr 1999 03:56:22 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: regex: I see THAT it works, but I don't see WHY
Message-Id: <639pf7.qe8.ln@magna.metronet.com>

sstarre@my-dejanews.com wrote:

: I don't understand how '?' works in a regex. 


   ? is overloaded in regexen.

   It is used for both matching zero or one (optional) "things"
   (as in your first use below), and for making a match non-greedy
   (as in your program below).


: The simple program below works
: fine, but WHY? It seems to me intuitively that the substitution line should be
: something like:

:   $s1 =~ s/(\:\:(.*)\:\:)?/$h{$1}/g; # **


   That will match *any* string whatsoever. Probably not what you want.

   It will match your $s1 below 41 times.

   It will even match when  $s1 = '';

   Because that pattern matches the null string.


   (you don't need any of those backslashes either)


: since the production that I'm concerned about minimizing is '::string::', not
: 'string'. (.*?) minimizes the chars BETWEEN the :: delimiters, which have no
: ambiguity. The only ambiguity lies in the delimiters themselves- which ones to
: choose (inner or outer)? 


   That is not the only ambiguity.


: The syntax (below) suggests that it minimizes the
: string, not the delimiters, yet somehow it works.

: Can someone please explain why? I'm pleased that it's working, but knowing why
: would be every better :)


   I'm not too sure that I understand what you are confused
   about, but I'll try anyway...



: my $s='my ::x1:: ::x2:: would have to be ::x3::';


   m/::(.*)::/ (if there wasn't greediness) can match that 
   string all of these ways:


: my $s='my ::x1:: ::x2:: would have to be ::x3::';
            ^^^^^^

: my $s='my ::x1:: ::x2:: would have to be ::x3::';
            ^^^^^^^^^

: my $s='my ::x1:: ::x2:: would have to be ::x3::';
            ^^^^^^^^^^^^^

: my $s='my ::x1:: ::x2:: would have to be ::x3::';
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

: my $s='my ::x1:: ::x2:: would have to be ::x3::';
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


   Perl can only match one of the alternatives.

   It allows you to choose to match greedily (the last one), or 
   non-greedily (the first one).



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


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

Date: 23 Apr 1999 09:42:26 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: regex: I see THAT it works, but I don't see WHY
Message-Id: <x74sm7bghp.fsf@home.sysarch.com>

>>>>> "DG" == Daniel Grisinger <dgris@moiraine.dimensional.com> writes:

  DG> Uri Guttman <uri@sysarch.com> writes:

  DG> 5- The lazy ?
  DG> ?.? ;                    # i'm done for the day
  >> 
  >> who really uses this (it is also deprecated)? 

  DG> I do.

why? it is deprecated, very obscure, and can be easily done with the
regular m// (as the camel says, just break out of the loop). if i were
to see m?? i might not even know what is is for a second. what benefit
do you get from only matching the first time it is used before a call to
reset? show some code where it actually is useful.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Fri, 23 Apr 1999 12:21:48 GMT
From: njc@dmc.uucp (Neil Cherry)
Subject: Re: Sending binary values?
Message-Id: <slrn7i0pjn.g2r.njc@dmc.uucp>

On Thu, 22 Apr 1999 22:31:52 -0700, Larry Rosler wrote:
>[Posted and a courtesy copy sent.]
>
>In article <7fnr2i$mrt$24@newsread.f.de.uu.net> on 22 Apr 1999 18:50:58 
>GMT, Neil Cherry <njc@dmc.uucp> says...
>... 
>> $a[0] = 0x24;
>> $a[1] = 0x05;
>> $a[2] = 0x00;
>> $a[3] = 0x01;
>...
>> I want:
>> 
>> !^E^@^A (that 4 character 0x24 0x05 0x00 0x01).
>
>my $packed = pack 'C*', @a; # or 'C4' in this case
>
>But that produces a $ as the first character.  0x21 produces a ! .

(Tried to send email but HP doesn't like home.net, says it lacks a
domain name. Looks like home.net is black listed).

Thanks, it turned out to be both. I accidently used unpack instead and
once I examined the RS232 output I noticed the $ instead of the !. The
code now works great! I guess I should get some rest before debugging.

-- 
Linux Home Automation           Neil Cherry             ncherry@home.net
http://members.home.net/ncherry                         (Text only)
http://meltingpot.fortunecity.com/lightsey/52           (Graphics GB)



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

Date: Fri, 23 Apr 1999 13:03:28 GMT
From: scott@sboss.net
To: Michael.Cameron@technologist.com
Subject: Re: Telnet problems
Message-Id: <7fpr2t$o79$1@nnrp1.dejanews.com>

In article <372051CF.AC692A7B@technologist.com>,
  Michael Cameron <Michael.Cameron@nospam.technologist.com> wrote:
> Post a code snippet showing the minimum amount of code which demonstrates your
> problem.
>
> Run perl -v and include its first line of output (I think it should be "This
> is perl, version 5.004_04 built for i386-linux" for RH5.2). You might also
> want to go and get the latest libnet bundle (including Net::Telnet) and
> reinstall it just to be sure.

# perl -v

This is perl, version 5.004_05 built for i386-linux
 ...

> I use RH5.2 and have some Solaris 2.5 and 2.6 boxes on other parts of the
> network which I can play with so at the very least I could try to reproduce
> your problem, although I have no problems with the following, could you try
> something similar:
>
> #!/usr/bin/perl -w
>   use strict;
>   use Net::Telnet ();
>   my $t = new Net::Telnet (Timeout => 10);
>   $t->open("HOSTNAME REMOVED");
>   $t->login("michael", "PASSWORD REMOVED");
>   my @lines = $t->cmd("/usr/bin/who");
>   print @lines;
>
> I will mail some of my ex-colleagues and see if the patch I made to the expect
> stuff is still around - the patch was on the Solaris box though, I can use
> Net::Telnet on my linux box with no problems.
>
> Another point to note, if you quit the telnet without properly closing down
> the session you might find that the remote system is somewhat confused (this
> happened while connecting to a really nasty VT100 implemenatation on a frame
> relay switch).If things get screwy then use a manual telnet to the system
> before tryning another automated one.
>
> HTH,
>
> Michael Cameron

Here is some of the code I have tried....


#!/usr/bin/perl -w # $|=1; $login="root"; $pass='password is removed'; use
Net::Telnet; # $t = new Net::Telnet (Timeout=>300); print "1";
$t->open("1.1.2.2"); # real IP removed so I do not get in trouble with
Security print "2"; $t->login($login,$pass); print "6"; print $t->cmd(String
=> "/bin/ls"); print "7"; $t->close; print ".\n";


Like I said, I have tried all sorts of variants of this and nothing seems to
work.  I will try your snippet of code this weekend and let you know on
Monday...

Thanks for all your help,
Scott


--
Scott Boss
Atlanta Perl Mongers Fearless Leader
website:   http://atlanta.pm.org
community: http://www.dejanews.com/~apm

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Fri, 23 Apr 1999 12:01:46 GMT
From: Jeremy Gurney <c4jgurney@my-dejanews.com>
Subject: Re: where is perlcore.dll?
Message-Id: <7fpnf9$kv2$1@nnrp1.dejanews.com>

In article <7fpgnc$bd3$1@nslave1.tin.it>,
  "Chris" <vallet@prismanet.com> wrote:
> I try to use the Win32::GUI module, but win98 gives an error: can't find the
> file "Perlcore.dll"...
>
> I have installed ActiveState Perl 5.09
>
> Thanks.

On my PC it's in c:\perl\bin (NT, AS5.09)

I've had a problem with a perl dll file going walkabout in the past, have a
look in c:\perl\bin and see if it's been re-named perlcore.bak or something.

If you still can't find it then either re-install perl or get someone to mail
it to you.

Jeremy Gurney
SAS Programmer  |  Proteus Molecular Design Ltd.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Fri, 23 Apr 1999 15:29:46 +0200
From: =?iso-8859-1?Q?J=FCrgen?= Ibelgaufts <ibelgaufts@gfc-net.de>
Subject: Re: where is perlcore.dll?
Message-Id: <372075CA.C05AD10F@gfc-net.de>



Chris wrote:
> 
> I try to use the Win32::GUI module, but win98 gives an error: can't find the
> file "Perlcore.dll"...
> 
> I have installed ActiveState Perl 5.09
> 
> Thanks.

I would suggest to use the Tk extension. With that one you can
write state-of-the-art GUIs - and they are highly portable to
non-Windows systems (OS/2, Linux, other UNIXes). Not that I
think that Win32::GUI were bad, but it works *only* on Microsoft
Windows.

Juergen Ibelgaufts


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

Date: Fri, 23 Apr 1999 14:11:30 GMT
From: snowhare@long-lake.nihongo.org (Benjamin Franz)
Subject: Re: yet another Abigail sig
Message-Id: <mc%T2.9$qP.16803@typhoon-sf.snfc21.pbi.net>

In article <MPG.118980f73700af9f98991a@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>
>In article <7fohdb$kui$1@news.smart.net> on 23 Apr 1999 01:12:11 GMT, 
>hymie! <hymie@lactose.smart.net> says...
> 
>> As a side note, I've been dying for a reason to post, so I could offer
>> up my own sig and see if anybody is impressed or merely looks down upon
>> me.  Alas, it's my only one, so let the looking-down-upon begin...
>> 
>> ..hymie!         http://www.smart.net/~hymowitz         hymie@lactose.smart.net
>> $_ = "abcdefghijklmnopqrstuvwxyz0123456789"; tr
>> /5g869fltymzhu01rv3qc2xdn7oabsw4jekpi/.\"\"\\;    AHJPaceeehiklnnnoprrrrstttu/;
>> eval;
>
>Well, the first statement should be:
>
>$_=join"",'a'..'z',0..9; 
>
>And the backslashes before the two double-quotes are superfluous 
>(superstitious?).  Other than that, it has some merit, I guess.  But 
>I've never written one myself, so who am I to judge yours?
>
>For your next exercise, try using xor (^) instead of tr.

Irritate the NSA. Use modular exponentiation.

-- 
# Benjamin Franz
$_='bfd59934ae3d4bde348887a3ae4587a311aeec44f26087a372';
my @a=m/(..)/g;foreach(map{hex}@a){my $n=257;
while($_--){$n=($n*257)%251};print chr($n)}


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

Date: 23 Apr 1999 14:31:24 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: yet another Abigail sig
Message-Id: <7fq07s$esr$1@client2.news.psi.net>

Larry Rosler (lr@hpl.hp.com) wrote on MMLXI September MCMXCIII in
<URL:news:MPG.118980f73700af9f98991a@nntp.hpl.hp.com>:
'' [Posted and a courtesy copy mailed.]
'' 
'' In article <7fohdb$kui$1@news.smart.net> on 23 Apr 1999 01:12:11 GMT, 
'' hymie! <hymie@lactose.smart.net> says...
'' > >> Abigail (abigail@fnx.com) wrote:
'' > 
'' > >>> : srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
'' > >>> : //=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"
'' >  
'' > While I don't pretend to understand what it does (yet), I tried to run it (as
'' > I always do), and came up with this
'' > 
'' > Hareektu arlJorhnesP ct
'' > 
'' > which I presume means that my random number generator is not seeded like
'' > hers?
'' 
'' I get this:
'' 
'' o JutPrerclrHtek naahe s
'' 
'' So your supposition is apparently correct.


I hardly think so. Unless '123456' means something else on your system.

But your random generator might use a different algorithm....



Abigail
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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 5463
**************************************

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