[19805] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2000 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 24 14:06:19 2001

Date: Wed, 24 Oct 2001 11:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1003946711-v10-i2000@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 24 Oct 2001     Volume: 10 Number: 2000

Today's topics:
        a search question <steve@NOSPAMdvdcc.com>
    Re: a search question (Jason Kohles)
    Re: a search question <BROWNHIK@Syntegra.Bt.Co.Uk>
    Re: a search question <steve@NOSPAMdvdcc.com>
    Re: a search question (Jason Kohles)
    Re: a search question <steve@NOSPAMdvdcc.com>
    Re: Formatting numbers - decimal places <Graham.T.Wood@oracle.com>
    Re: Good Literature <zecho@radicalmatter.com>
    Re: Hiding the content of a Perl Script <djberge@qwest.com>
    Re: Jon Ericson <mjcarman@home.com>
    Re: Jon Ericson <postmaster@127.0.0.1>
    Re: Jon Ericson <comdog@panix.com>
    Re: Length of an Array or hash (Mark Jason Dominus)
    Re: matching (Tad McClellan)
    Re: need value of struct for system() <bogus@bogus.com>
        one-liner solution sought ()
    Re: one-liner solution sought <rsherman@ce.gatech.edu>
    Re: one-liner solution sought (John J. Trammell)
    Re: one-liner solution sought <uri@sysarch.com>
    Re: one-liner solution sought <caughran@chem.uga.edu>
    Re: one-liner solution sought <dtweed@acm.org>
        Perl and sendmail <meuzelaj@student.dontspam.gvsu.edu>
    Re: Perl and sendmail <hillr@ugs.com>
        Plaintext to passwd file? <plarkin@beth.k12.pa.us>
    Re: Plaintext to passwd file? (Mark Jason Dominus)
        Reading different string input <martin_andersen_90@yahoo.com>
    Re: Reading different string input <darkon@one.net>
    Re: Search File <darkon@one.net>
    Re: Updating Solaris default installed Perl (Garry Williams)
    Re: What exactly will "make install" do for my module? <nospam-abuse@ilyaz.org>
    Re: What's wrong with File::Find (Mark Jason Dominus)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 24 Oct 2001 10:16:59 -0500
From: "Steve Jackson" <steve@NOSPAMdvdcc.com>
Subject: a search question
Message-Id: <h1BB7.49563$6i7.5873744@e420r-atl1.usenetserver.com>


I guess I'm a bit confused on how to do this.

I have a variable with a massive amount of data (for example):

$thisistheone = "Hi how are you.  I am fine.  What would you like?  I would
like a six pack please.  The cost for that is $7.00 plus tax.  I will take
it.  Sold.";

What I need is first search for the word "cost" as a keyword.  When it finds
it, I need it to then put the next dollar amount which is "$7.00" into a new
variable.  This way it will put the dollar amount in the variable only after
the keyword since there might be more than one $ amount in the original
variable.

Any thoughts?

Thanks all!

Steve







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

Date: 24 Oct 2001 15:39:31 GMT
From: usenet@jasonkohles.com (Jason Kohles)
Subject: Re: a search question
Message-Id: <slrn9tdo1q.la2.usenet@poseidon.mediabang.com>

On Wed, 24 Oct 2001 10:16:59 -0500, Steve Jackson wrote:
>
>$thisistheone = "Hi how are you.  I am fine.  What would you like?  I would
>like a six pack please.  The cost for that is $7.00 plus tax.  I will take
>it.  Sold.";
>
>What I need is first search for the word "cost" as a keyword.  When it finds
>it, I need it to then put the next dollar amount which is "$7.00" into a new
>variable.  This way it will put the dollar amount in the variable only after
>the keyword since there might be more than one $ amount in the original
>variable.
>
$thisistheone =~ /cost.*?(\$[\d\.]+)/;

-- 
Jason S Kohles
email@jasonkohles.com          http://www.jasonkohles.com/


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

Date: Wed, 24 Oct 2001 16:51:23 +0100
From: "Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk>
Subject: Re: a search question
Message-Id: <9r6o8n$442$1@pheidippides.axion.bt.co.uk>

Try this reg-exp.

$thisistheone = 'Hi how are you.  I am fine.  What would you like?  I would
like a six pack please. The cost for that is $5.00 plus tax.  I will take
it.  Sold.';

if  ( ($cost) = ( $thisistheone =~ /cost[^\$]*\$(\d*(\.\d+)?)/ )   )
   {
   print "$cost\n"
   }

This only works if there is a digit or decimal point straight after the
first dollar sign after the word cost.


Hope this helps
Kevin Brownhill


"Steve Jackson" <steve@NOSPAMdvdcc.com> wrote in message
news:h1BB7.49563$6i7.5873744@e420r-atl1.usenetserver.com...
>
> I guess I'm a bit confused on how to do this.
>
> I have a variable with a massive amount of data (for example):
>
> $thisistheone = "Hi how are you.  I am fine.  What would you like?  I
would
> like a six pack please.  The cost for that is $7.00 plus tax.  I will take
> it.  Sold.";
>
> What I need is first search for the word "cost" as a keyword.  When it
finds
> it, I need it to then put the next dollar amount which is "$7.00" into a
new
> variable.  This way it will put the dollar amount in the variable only
after
> the keyword since there might be more than one $ amount in the original
> variable.
>
> Any thoughts?
>
> Thanks all!
>
> Steve
>
>
>
>
>




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

Date: Wed, 24 Oct 2001 11:04:54 -0500
From: "Steve Jackson" <steve@NOSPAMdvdcc.com>
Subject: Re: a search question
Message-Id: <EIBB7.12744$Z2.2065045@e420r-atl2.usenetserver.com>


Here's the code.  For some reason its only coming up with a cost of "1"?
thanks in advance!

use LWP::UserAgent;

$ua = new LWP::UserAgent;
$ua->agent("$0/0.3"); #give your agent an ID like Mozilla

$location='http://www.amazon.com/exec/obidos/ASIN/B00003CX5P/';

$req = new HTTP::Request 'GET', $location;
$req->header('Accept' => 'text/html');

$res = $ua->request($req);
$doc=$res->content;# get the content

$whatgive = "Our Price";

$cost = ($doc =~ /$whatgive[^\$]*\$(\d*(\.\d+)?)/);

print "Content-type: text/html\n\n";
print "The price for Amazon item B00003CX5P is $cost";



"Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk> wrote in message
news:9r6o8n$442$1@pheidippides.axion.bt.co.uk...
> Try this reg-exp.
>
> $thisistheone = 'Hi how are you.  I am fine.  What would you like?  I
would
> like a six pack please. The cost for that is $5.00 plus tax.  I will take
> it.  Sold.';
>
> if  ( ($cost) = ( $thisistheone =~ /cost[^\$]*\$(\d*(\.\d+)?)/ )   )
>    {
>    print "$cost\n"
>    }
>
> This only works if there is a digit or decimal point straight after the
> first dollar sign after the word cost.
>
>
> Hope this helps
> Kevin Brownhill
>
>
> "Steve Jackson" <steve@NOSPAMdvdcc.com> wrote in message
> news:h1BB7.49563$6i7.5873744@e420r-atl1.usenetserver.com...
> >
> > I guess I'm a bit confused on how to do this.
> >
> > I have a variable with a massive amount of data (for example):
> >
> > $thisistheone = "Hi how are you.  I am fine.  What would you like?  I
> would
> > like a six pack please.  The cost for that is $7.00 plus tax.  I will
take
> > it.  Sold.";
> >
> > What I need is first search for the word "cost" as a keyword.  When it
> finds
> > it, I need it to then put the next dollar amount which is "$7.00" into a
> new
> > variable.  This way it will put the dollar amount in the variable only
> after
> > the keyword since there might be more than one $ amount in the original
> > variable.
> >
> > Any thoughts?
> >
> > Thanks all!
> >
> > Steve
> >
> >
> >
> >
> >
>
>





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

Date: 24 Oct 2001 16:31:01 GMT
From: usenet@jasonkohles.com (Jason Kohles)
Subject: Re: a search question
Message-Id: <slrn9tdr2c.qfo.usenet@poseidon.mediabang.com>

On Wed, 24 Oct 2001 11:04:54 -0500, Steve Jackson wrote:
>
>Here's the code.  For some reason its only coming up with a cost of "1"?
>thanks in advance!
>
You need to read the example more carefully.

>$cost = ($doc =~ /$whatgive[^\$]*\$(\d*(\.\d+)?)/);
($cost) = ($doc =~ /$whatgive[^\$]*\$(\d*(\.\d+)?)/);

-- 
Jason S Kohles
email@jasonkohles.com          http://www.jasonkohles.com/


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

Date: Wed, 24 Oct 2001 11:37:49 -0500
From: "Steve Jackson" <steve@NOSPAMdvdcc.com>
Subject: Re: a search question
Message-Id: <vbCB7.12777$Z2.2069428@e420r-atl2.usenetserver.com>

LOL i'm a dummy :)  Thanks so much!  It works



"Jason Kohles" <usenet@jasonkohles.com> wrote in message
news:slrn9tdr2c.qfo.usenet@poseidon.mediabang.com...
> On Wed, 24 Oct 2001 11:04:54 -0500, Steve Jackson wrote:
> >
> >Here's the code.  For some reason its only coming up with a cost of "1"?
> >thanks in advance!
> >
> You need to read the example more carefully.
>
> >$cost = ($doc =~ /$whatgive[^\$]*\$(\d*(\.\d+)?)/);
> ($cost) = ($doc =~ /$whatgive[^\$]*\$(\d*(\.\d+)?)/);
>
> --
> Jason S Kohles
> email@jasonkohles.com          http://www.jasonkohles.com/





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

Date: Wed, 24 Oct 2001 16:31:41 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: Formatting numbers - decimal places
Message-Id: <3BD6DEDD.8254AACF@oracle.com>

This is a multi-part message in MIME format.
--------------EE162242E25D1B8E683759A2
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit


Tomas wrote:

> What do I have to do to make the 13.1 output as 13.10?

$variable=13.1
$variable2=sprintf("%.2f",$variable);

formats the number as a float with 2 decimal places and rounds it if it has
more than 2 decimal places.

Graham Wood

--------------EE162242E25D1B8E683759A2
Content-Type: text/x-vcard; charset=UTF-8;
 name="Graham.T.Wood.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Graham Wood
Content-Disposition: attachment;
 filename="Graham.T.Wood.vcf"

begin:vcard 
n:;Graham
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:Graham.T.Wood@oracle.com
fn:Graham Wood
end:vcard

--------------EE162242E25D1B8E683759A2--



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

Date: Wed, 24 Oct 2001 17:19:51 GMT
From: "Zecho" <zecho@radicalmatter.com>
Subject: Re: Good Literature
Message-Id: <XKCB7.17832$IR4.10389687@news1.denver1.co.home.com>

> I've been in contact with the author over the last couple of months and
> I'm currently working on a (very long) list of technical errors and
> suggestions on improvements. Jaqueline has already indicated that she'll
> be happy to include my fixes in the next edition. Hopefully, this will
> end up with another much improved beginners book on the bookshelves.
> 

Dave, might I suggest co-authoring the next release?  A collaborative
effort is much better than suggestions for improvement, IMHO.


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

Date: Wed, 24 Oct 2001 11:42:14 -0500
From: "Mr. Sunblade" <djberge@qwest.com>
Subject: Re: Hiding the content of a Perl Script
Message-Id: <P7CB7.158$EC.84984@news.uswest.net>


"Dan Sugalski" <dan@tuatha.sidhe.org> wrote in message
news:NuAB7.123626$NT3.12895051@news1.rdc1.ct.home.com...
> Kalin <kalin@vivax-tech.com> wrote:
> > Hi,
>
> > I'm working on a project that requires the content of the Perl Scripts
> > not to be seen. I was wondering if there is a way to do that?
>
> A perfect application for ACME::Bleach.
>
> Dan

Heh - funny.

"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:3bd6d5b1@news.microsoft.com...

>RTFM!
>This very question with almost exactly the same wording in the subject had
>been asked just 2 or 3 days ago. Don't you read before you write?

Ah, there's the perl newsgroup I know and love.  Not!

But I digress...

Kalin,

It depends on how much security you need.  Are you just trying to hide
login/password information (for telnet, dbi, etc)?  If so, I find that using
the .netrc file is very handy (see the Net::Netrc module for more info) for
that sort of thing (or any .rc file that you want to make on your own).

If it's a matter of protecting source code in general, then it gets more
complex, but like the faq says, someone will always be (potentially) able to
decrypt it.  A simple and effective method would be to use Rot13 on the
source code.  Then, from another script, decode the source and execute it.
Unless someone knows the degree of rotation, your source code is safe.  It's
easy, and will stop all but determined crackers.

On the other hand, you could always just compile it.

Regards,

Mr. Sunblade








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

Date: Wed, 24 Oct 2001 09:44:24 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Jon Ericson
Message-Id: <3BD6D3C8.C7C5F121@home.com>

SJC wrote:
> 
> What do you think of this Jon Ericson?
>
> Personally I think he is a idiot. What do yo think? Lets have your
> opinion?

Why cares what I think? Would my opinion somehow validate your own?

> Who thinks he should be banned?

Presumably people who have an entry for him in their killfile. (Which,
incidentally, is someplace you're likely to end up if you keep posting
off-topic crap like this.)

-mjc


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

Date: Wed, 24 Oct 2001 17:09:55 +0100
From: Anthony Peacock <postmaster@127.0.0.1>
Subject: Re: Jon Ericson
Message-Id: <3BD6E7D3.928A8BB1@127.0.0.1>

SJC wrote:
> 
> Hi
> 
> What do you think of this Jon Ericson?
> 
> Personally I think he is a idiot. What do yo think? Lets have your opinion?
> 
> Who thinks he should be banned?

Who is Jon Ericson?

Why should he be banned?

What do you want to ban him from doing?

And what has this to do with Perl?


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

Date: Wed, 24 Oct 2001 12:18:47 -0400
From: brian d foy <comdog@panix.com>
Subject: Re: Jon Ericson
Message-Id: <comdog-C849B1.12184724102001@news.panix.com>

In article <143f4c01.0110240602.114c1450@posting.google.com>, 
cooperste@hotmail.com (SJC) wrote:

> What do you think of this Jon Ericson?

it doesn't matter what i think of him.  at least he uses a name

> Personally I think he is a idiot. What do yo think? Lets have your opinion?

if you don't like him then killfile him and be done with it.  
you don't need anyone's permission to do that, and you won't 
have to see his posts. 

> Who thinks he should be banned?

considering that you can't ban anyone, and that your post is
extremely puerile, off-topic, and a troll, perhaps you should 
be banned.

*plonk*

-- 
brian d foy <comdog@panix.com> - Perl services for hire
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html



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

Date: Wed, 24 Oct 2001 17:55:11 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Length of an Array or hash
Message-Id: <3bd7007e.9cb$160@news.op.net>

In article <9r64vq$aet$1@newstoo.ericsson.se>,
Peter <peter_laranc@yahoo.com> wrote:
>and How can i check if an array or hash is empty or not ?
>
>If an array looks like
>[
> '192.66.10.80',
> '192.66.10.81',
> '147.215.1.12',
> '192.66.10.88',
> '192.66.10.83',
>];

if (@$array) {
  # it is not empty
} else {
  # it is empty
}

unless (@$array) {
  # it is empty
}

if (@$array == 0) {
  # it is empty
} else {
  # it is not empty
}

if (@$array > 0) {
  # it is not empty
} else {
  # it is
}

>and the hash looks like
>
>{  
>   2 => {
> Name  =>'Patrik', 
>    },
>
>   3 => {
> Name  =>'Mark', 
>    },
>};

if (%$hash) {
  # it is not empty
} else {
  # it is empty
}

unless (%$hash) {
  # it is empty
}

>Thanks alot   Peter

Hope this helps.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Wed, 24 Oct 2001 15:25:29 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: matching
Message-Id: <slrn9tdkls.meq.tadmc@tadmc26.august.net>

Lex Thoonen <lex@nospam.peng.nl> wrote:
>
>I've got the following code:
>
>foreach $key (keys %delete_list) {
>
>		  my $dir = $build_photo_path;
>		  my (@files) = ();
>		  &header;
>          opendir(DIR, $dir) || &err("can't open : $!");          
>		  @files = grep { /$key\.*/i } readdir(DIR);


That will match:  contents of $key followed by zero or more dot chars.

   eg.   19......jpg

Is that what you wanted to match?

You likely need some anchors in your pattern too.


>		  closedir(DIR);
>
>		  if ($#files > -1) {


That if() is useless. $#files will always be greater than negative one!

What did you hope accomplish with that test?


>	      foreach (@files) {
>		unlink("$dir/$_") || &err("can't delete $_ : $!");
>			  }
>	      }
>}
>
>But I have one problem...
>
>$key can be a number, 
             ^^^^^^^^

12.45

1e10

5+5

Those are all "numbers" too. I will assume you mean "all digit characters"
instead of "number".


>an id from my database.


But below you seem to be indicating that $key can contain
non-digit characters, so I don't know what you mean here.

Did you mean the base part of the filename (ie. excluding the
filename extension) can be only digit characters?


>Any of these numbers can have images in a folder:

>for example: 19a.jpg 19b.gif 19c.JpeG
>
>The problem is the a, b and the c
>
>What I would like this script to do is:
>
>check for all records that are 19 ($key) followed directly with a
>letter. (so, don't take 191a.jpg for example)


You have not specified what you need completely enough to
give a definitive answer, so here is a WAG:

   my @files = grep { /^$key[abc]\..*$/i } readdir(DIR);


>Delete them


It appears that you already know how to delete the files.


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


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

Date: Wed, 24 Oct 2001 12:03:36 -0500
From: MJ <bogus@bogus.com>
Subject: Re: need value of struct for system()
Message-Id: <3BD6F468.63BC06D4@bogus.com>

And the answer is . . .

MJ wrote:
> 
> I have a structure:
> 
>    struct vc_struct => {
>         vm1     =>      '$',
>    };
> 
> How do I refer vm1 to do a system call?
> 
> I try:
> 
>         if ( system("rcp $RCCVAR/$vc->vm1 $system1:$RCCVAR/$vc->vm1") ) {

         if ( system("rcp $RCCVAR/$vc->{vm1} $system1:$RCCVAR/$vc->{vm1}") ) {

I had to put braces around the structure member.

MJ


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

Date: Wed, 24 Oct 2001 16:15:19 +0000 (UTC)
From: kmead@socrates.Berkeley.EDU ()
Subject: one-liner solution sought
Message-Id: <9r6pen$l3r$1@agate.berkeley.edu>

Can someone come up with a one-line perl script which will pad out
the value part of a name="value" to be exactly 10 characters long?

For example, change
   name="value"         ==> name="valuexxxxx"
   name=""              ==> name="xxxxxxxxxx"
   name="1234567890123" ==> name="1234567890123"

Thanks

Keith


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

Date: Wed, 24 Oct 2001 16:29:40 +0000 (UTC)
From: Robert Sherman <rsherman@ce.gatech.edu>
Subject: Re: one-liner solution sought
Message-Id: <9r6q9k$sfv$1@news-int.gatech.edu>

kmead@socrates.Berkeley.EDU () wrote:
> Can someone come up with a one-line perl script which will pad out
> the value part of a name="value" to be exactly 10 characters long?
> 
> For example, change
>    name="value"         ==> name="valuexxxxx"
>    name=""              ==> name="xxxxxxxxxx"
>    name="1234567890123" ==> name="1234567890123"
> 
> Thanks
> 
> Keith

perldoc -f sprintf
-- 
robert sherman
css, cee
georgia institute of technology
atlanta, ga, usa


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

Date: Wed, 24 Oct 2001 11:29:54 -0500
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: one-liner solution sought
Message-Id: <slrn9tdr41.6cv.trammell@haqq.hypersloth.net>

On Wed, 24 Oct 2001 16:15:19 +0000 (UTC), kmead@socrates.Berkeley.EDU wrote:
> Can someone come up with a one-line perl script which will pad out
> the value part of a name="value" to be exactly 10 characters long?
> 
> For example, change
>    name="value"         ==> name="valuexxxxx"
>    name=""              ==> name="xxxxxxxxxx"
>    name="1234567890123" ==> name="1234567890123"
> 

s/"(.*?)"/sprintf(q["%s%s"],$1, "x" x (10-length($1)))/e;



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

Date: Wed, 24 Oct 2001 16:32:16 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: one-liner solution sought
Message-Id: <x7itd52e2q.fsf@home.sysarch.com>

>>>>> "XX" ==   <kmead@socrates.Berkeley.EDU> writes:

  XX> Can someone come up with a one-line perl script which will pad out
  XX> the value part of a name="value" to be exactly 10 characters long?

  XX> For example, change
  XX>    name="value"         ==> name="valuexxxxx"
  XX>    name=""              ==> name="xxxxxxxxxx"
  XX>    name="1234567890123" ==> name="1234567890123"

FAQ

perldoc -q pad

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs  --------------------------  http://jobs.perl.org


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

Date: Wed, 24 Oct 2001 12:35:00 -0400
From: Joel Caughran <caughran@chem.uga.edu>
Subject: Re: one-liner solution sought
Message-Id: <3BD6EDB4.D6CF368F@chem.uga.edu>

Keith,

I'm not sure if you wanted the padding to be x's or spaces.  Here is one
way using sprintf.  I'm sure there are better.

Joel
-- 
Joel A Caughran                 caughran@chem.uga.edu
Chemistry Learning Center       caughran@uga.edu
Department of Chemistry
University of Georgia           (706) 542-1906 voice
Athens, Georgia 30602-2556      (706) 542-9454 fax

#!perl

$name = 'value';
$name = sprintf "%-10s", $name;
print "[$name]\n";		# brackets used to frame string

$name = '';
$name = sprintf "%-10s", $name;
print "[$name]\n";

$name = '1234567890123';
$name = sprintf "%-10s", $name;
print "[$name]\n";



kmead@socrates.Berkeley.EDU wrote:
> 
> Can someone come up with a one-line perl script which will pad out
> the value part of a name="value" to be exactly 10 characters long?
> 
> For example, change
>    name="value"         ==> name="valuexxxxx"
>    name=""              ==> name="xxxxxxxxxx"
>    name="1234567890123" ==> name="1234567890123"
> 
> Thanks
> 
> Keith


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

Date: Wed, 24 Oct 2001 16:45:20 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: one-liner solution sought
Message-Id: <3BD6EEBC.AAA6E6D5@acm.org>

kmead@socrates.Berkeley.EDU wrote:
> Can someone come up with a one-line perl script which will pad out
> the value part of a name="value" to be exactly 10 characters long?
> 
> For example, change
>    name="value"         ==> name="valuexxxxx"
>    name=""              ==> name="xxxxxxxxxx"
>    name="1234567890123" ==> name="1234567890123"

You examples make the value part "at least" 10 characters long:

   s/(?<=")(.*)(?=")/$1."x"x(10-length $1)/e;

-- Dave Tweed


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

Date: Wed, 24 Oct 2001 11:07:29 -0400
From: "Moitz" <meuzelaj@student.dontspam.gvsu.edu>
Subject: Perl and sendmail
Message-Id: <ttdmisq86rlq8e@corp.supernews.com>

I'm not exactly sure if this is a sendmail question or a perl question.

I'm trying to get my script to send two e-mails back-to-back, one to myself,
and one to whoever fills out a form on our webpage.  It sends the one to me
fine, but nothing shows up on the other end.  Here's what I'm doing:

$MAIL_PROG = "/usr/bin/sendmail";

&sendEmail;
&sendConfirm;

sub sendEmail() {
    open (MAIL, "|$MAIL_PROG -t");
    print MAIL ("To: $toAddress\n");
    print MAIL ("From: $fromAddress\n");
    print MAIL ("Subject: $subject\n\n");
    # Body of e-mail
    close (MAIL);
}

sendConfirm is the same as sendEmail, only with the to and from addresses
reversed.

Any help would be great, I'm trying to get this webpage into production by
the end of next week, and this has me stuck.

moitz




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

Date: Wed, 24 Oct 2001 08:20:35 -0700
From: "Ron Hill" <hillr@ugs.com>
Subject: Re: Perl and sendmail
Message-Id: <3bd6dac7$1@usenet.ugs.com>


"Moitz" <meuzelaj@student.dontspam.gvsu.edu> wrote in message
news:ttdmisq86rlq8e@corp.supernews.com...
> I'm not exactly sure if this is a sendmail question or a perl question.
>
> I'm trying to get my script to send two e-mails back-to-back, one to
myself,
> and one to whoever fills out a form on our webpage.  It sends the one to
me
> fine, but nothing shows up on the other end.  Here's what I'm doing:
>
> $MAIL_PROG = "/usr/bin/sendmail";
>
> &sendEmail;
> &sendConfirm;
>
> sub sendEmail() {
>     open (MAIL, "|$MAIL_PROG -t");
>     print MAIL ("To: $toAddress\n");
>     print MAIL ("From: $fromAddress\n");
>     print MAIL ("Subject: $subject\n\n");
>     # Body of e-mail
>     close (MAIL);
> }
>
> sendConfirm is the same as sendEmail, only with the to and from addresses
> reversed.
>
> Any help would be great, I'm trying to get this webpage into production by
> the end of next week, and this has me stuck.

from perldoc -q mail


How do I send mail?

           Use the "sendmail" program directly:

               open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq")
                                   or die "Can't fork for sendmail: $!\n";
               print SENDMAIL <<"EOF";
               From: User Originating Mail <me\@host>
               To: Final Destination <you\@otherhost>
               Subject: A relevant subject line

               Body of the message goes here after the blank line
               in as many lines as you like.
               EOF
               close(SENDMAIL)     or warn "sendmail didn't close nicely";




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

Date: Wed, 24 Oct 2001 13:39:48 -0400
From: "Patrick J. Larkin" <plarkin@beth.k12.pa.us>
Subject: Plaintext to passwd file?
Message-Id: <B7FC7523.D7E6%plarkin@beth.k12.pa.us>

I have a giant list of usernames and plain text passwords.  I wrote a simple
script to make an htpasswd file out of them but I don't know how to encrypt
the passwords!  I thought I could use the crypt() function but that asks for
a SALT?

I thought I could do something simple like:

$public_pw = crypt($password);

Obviously, I need a SALT after $password.  What should I put there?

Sorry if this question is really lame.

P.



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

Date: Wed, 24 Oct 2001 17:51:36 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Plaintext to passwd file?
Message-Id: <3bd6ffa8.9ba$3cf@news.op.net>

In article <B7FC7523.D7E6%plarkin@beth.k12.pa.us>,
Patrick J. Larkin <plarkin@beth.k12.pa.us> wrote:
>I have a giant list of usernames and plain text passwords.  I wrote a simple
>script to make an htpasswd file out of them but I don't know how to encrypt
>the passwords!  I thought I could use the crypt() function but that asks for
>a SALT?
>
>I thought I could do something simple like:
>
>$public_pw = crypt($password);
>
>Obviously, I need a SALT after $password.  What should I put there?

On systems that use a salt, it is usually a string of to characters
chosen from the set ('A'..'Z', 'a'..'z', '0'..'9', '.', '/').  The
particular salts don't matter, but you want to choose them so that
every password has a different salt, if possible.

Probably the simplest thing you can do that will work is:

        my $cur_salt_num = 0;
        sub next_salt {
          my @chars = ('A'..'Z', 'a'..'z', '0'..'9', '.', '/');
          my $salt = join '', @chars[$cur_salt_num / 64, $cur_salt_num % 64];
          ++$cur_salt_num;
          $cur_salt_num = 0 if $cur_salt_num == 4096;
          return $salt;
        }

        while (...) {
          my ($username, $password) = ...;
          my $crypted_password = crypt($password, next_salt());
          print "$username:$crypted_password\n";
        }

This uses all the possible salts in order until each one has been
used, and then starts over.

>Sorry if this question is really lame.

Not at all.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Wed, 24 Oct 2001 19:04:20 +0200
From: "Martin" <martin_andersen_90@yahoo.com>
Subject: Reading different string input
Message-Id: <9r6r3p$m0p$1@newstoo.ericsson.se>

Hi

Could some one please tell  me how  can i save different string format in
different variable, for example if i have an input string like:

$input = "pcNameInOffic";
$input = "pcUnitName.20.24.20.20.4.0.0";

If the input has a format like  pcNameInOffic, i want to save it in
$nameInput, and
If the input has a format like pcUnitName.20.24.20.20.4.0.0 i want to save
its content in $unitInput.


Thanks       Martin









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

Date: Wed, 24 Oct 2001 17:31:07 -0000
From: David Wall <darkon@one.net>
Subject: Re: Reading different string input
Message-Id: <Xns9144896EF1822darkononenet@207.126.101.97>

"Martin" <martin_andersen_90@yahoo.com> wrote on 24 Oct 2001:

> Could some one please tell  me how  can i save different string format
> in different variable, for example if i have an input string like:
> 
> $input = "pcNameInOffic";
> $input = "pcUnitName.20.24.20.20.4.0.0";
> 
> If the input has a format like  pcNameInOffic, i want to save it in
> $nameInput, and
> If the input has a format like pcUnitName.20.24.20.20.4.0.0 i want to
> save its content in $unitInput.

my ($nameInput, $unitInput);
if    ( $input =~ /^pcNameInOffic/ ) { $nameInput = $input }
elsif ( $input =~ /^pcUnitName/    ) { $unitInput = $input }

is one way to do it.

The above are very basic regular expressions.  For more info, see perlre 
in the documentation that comes with Perl.

-- 
David Wall
darkon@one.net


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

Date: Wed, 24 Oct 2001 16:36:02 -0000
From: David Wall <darkon@one.net>
Subject: Re: Search File
Message-Id: <Xns9144801828FB0darkononenet@207.126.101.97>

"Geoff Clark" <gclark@wavetel.com> wrote on 24 Oct 2001:

> #!/usr/bin/perl

#!/usr/bin/perl -w

Enabling warnings will give you all sorts of useful error messages.  

use strict;

is also highly recommended, as it makes you be much more careful with your 
code.  Among other things, with strict enabled you have to declare your 
variables before you use them, which would have informed you about one of 
the mistakes below. ($results)

> 
> #Search for IP by MAC
> 
> $dhcpfile = "dhcp.db";

What is this variable for?  You didn't use it when you opened the file 
(below).

> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
> @pairs = split(/&/, $buffer);
> foreach $pair (@pairs) {
>  ($mac, $value) = split(/=/, $pair);
>  $value =~ tr/+/ /;
>  $value=~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>  $value =~ s/~!/ ~!/g;
>  $FORM{$mac} = $value;
> }

You're generally better off using CGI.pm unless you have a really good 
reason for not doing so.  

> 
> $searchstr = $FORM{'mac'};
> 
> open (DHCP, "dhcp.db") or dienice("Can't open dhcp.txt: $! \n");

It's good that you checked the open, but why did you write your own die() 
function?  

> @dhcp = <DHCP>;

It's usually more efficient to just read the file a line at a time instead 
of slurping the whole thing into an array.

while (<DHCP>) {
    # do stuff with a line
    # like printing out parts of it if you find a match
}


> close(DHCP);
> 
> print "Content-type:text/html\n\n";
> print "<html><head><title>Search Results</title></head>\n";
> print "<body><h3>Search Results</h3>\n";

Using CGI.pm would make this easier.  If $query is your CGI object, you 
could just write

print $query->header, 
      $query->start_html("Search Results"),
      $query->h3("Search Results"); # h3 instead of h1?

I'm not sure why you're making the first header h3 instead of h1.  I 
suspect you're using it because of the side effect it has of using a 
particular font size and weight in your browser.  Style sheets are the 
recommended way to set fonts -- but that's an issue for another group, and 
not relevant to Perl.

> 
> @results = grep(/$searchstr/i,@dhcp);

You might want to check out quotemeta(), \Q and \E.

> $found = 0;
> if ($results >= 0) {

Where did $results come from?  You haven't used it before (that you've 
shown).  If you had enabled strict and warnings at the beginning of the 
program perl would have warned you about this. (Name "main::results" used 
only once: possible typo at ...) As it is, $results >= 0 is always true.

I think what you meant to do was check to see if @results had anything in 
it.  In that case,

if (@results > 0) {

is one way of doing it.


>  foreach $i (@results) {
>  chomp($i);
>  ($mac,$blank,$ip,$server,$lease,$name) = split(/\|/,$i);

This is ok if you reformatted the file the way you wanted, but you could 
just leave the file alone and say 

($mac,$blank,$ip,$server,$lease,$name) = split /\s+/, $i;



>  if ($mac =~ $searchstr) {

I don't think this line is doing what you expect it to do.  I suspect you 
want something like

if ($mac =~ /$searchstr/i) {

Again, check out quotemeta(), \Q, and \E.



>   print "$mac ($ip) - $name<br>\n";
>   $found = 1;
>  }
>   }
>  } else {
>   print "No results found.<p>\n";
>  }
> 
>  if ($found == 0) {
>   print "No results found.<p>\n";
>  }
> 
> ###Sub Routines Start Here###
> sub dienice {
>  my ($msg) = @_;
>  print "Error\n";
>  print $msg;
>  exit;
> }

Perl already has a die() function; why write your own?

Don't take any of this personally.  I'm criticizing the code, not you.  
I've made all the the same mistakes and more.  (If I've made a mistake 
somewhere in my comments, I hope someone will correct/criticize my 
comments, too...)

-- 
David Wall
darkon@one.net


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

Date: Wed, 24 Oct 2001 16:01:40 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Updating Solaris default installed Perl
Message-Id: <slrn9tdpf4.q04.garry@zfw.zvolve.net>

On Wed, 24 Oct 2001 11:56:22 +0200, Ronan O'Connor
<ronan.oconnor@materna.nl> wrote:

> I've made a clean installation of Sun Solaris 2.8 on an Intel box. Solaris
> 2.8 comes with Perl 5.0.0.5 preinstalled. 

That's 5.005 .  

> When I ran "perl -MCPAN -e shell",
> the first time, a perl configuration script was run (not the one asking
> which country you are in, your WAIT server etc... , but rather the script
> which asks what platform you are running, what C compiler you use,  how long
> your INT is and so on). Unfortunately, I ran the configure script in default
> mode, which I believe set my C compiler to be cc rather than the one I have
> gcc. I would now like to rerun this config script and reset my C compiler
> (which I think is causing lots of problems installing various Perl
> Modules!). Does anyone know how to do this?

This will probably not be possible.  That is, you will probably not be
able to install modules using gcc on this installation.  Perl is not
designed to allow such a thing.  (Others may be able to explain a way
to do this.)  

I would just install another version (5.6.1 is current) using the
compiler of your choice and you won't have to solve this problem.  

-- 
Garry Williams


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

Date: Wed, 24 Oct 2001 16:42:23 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: What exactly will "make install" do for my module?
Message-Id: <9r6r1f$m33$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Edwin =?iso-8859-1?Q?G=FCnthner?= 
<edgue@web.de>], who wrote in article <3BD6B28A.1E684835@web.de>:
> Hi there,
> 
> I developped a new module that needs to run on a lot of OS/2 
> machines. All those machines do not have make/gcc installed,
> [I need gcc to compile some xs stuff] so there is no way
> to tell my users: 
> 
> *get perl, 
> *get my module, 
> *do "perl Makefile.pl", 
> *do "make install"
> 
> because they would need to install make+gcc to do it this
> way. Therefore I am wondering if it is possible to 
> create a simple ZIP file that holds all the stuff that
> is necessary for my module. Is that enough? Or is
> it necessary to modify existing files of the Perl 
> distribution in order to "install" new modules?

I made a patch for a MakeMaker several years ago to address exactly
this problem.  I think it was lost - or deliberately skipped to pave
way for this PPM monster (?).

This patch added a install_default() rule to MakeMaker which would
install the contents of ./blib into the directories specific for the
given machine [*].  So you could just ship your ./blib, ./t, and
Makefile, and would ask the user to do

  make test_local
  make install_local

test_local would just run

 perl -Mblib t/whatever

and install_local calls install_default().

Ilya

[*] As oppesed to install(), which uses the directories hardwired into
    the Makefile.  With install_default(), you can move the Makefile
    to another machine, and it will do a "right thing".

P.S.  The patch also created Makefile rules to *generate* the complete
      binary distribution, including READMEs etc.


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

Date: Wed, 24 Oct 2001 18:04:21 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: What's wrong with File::Find
Message-Id: <3bd702a5.9fe$8f@news.op.net>

In article <vtpu7djhh2.fsf@liffe.com>,  <brianr@liffe.com> wrote:
>"Alexander Farber (EED)" <eedalf@eed.ericsson.se> writes:
>
>> Hi,
>> 
>> I think it lacks a possibility to pass arguments to
>> the wanted subroutine - like find ({wanted => \&mysub,
>>                                     args   => \@myargs}, '/', '/tmp');
>> 
>> and that's why I have to use global variables or closures - for example 
>> when I'm trying to recursively parse some files and put extracted data 
>> into a data structure - I have to make this data structure global. Or 
>> do I misunderstand something?
>
>Although your suggestion sounds interesting, I think that the following
>has the same effect:
>
>find(sub { mysub(@myargs) }, '/', '/tmp');

It has the same effect because it is the same suggestion.  You are
using a closure, as Alexander suggested.


-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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


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