[23930] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6131 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 13 18:05:51 2004

Date: Fri, 13 Feb 2004 15:05:06 -0800 (PST)
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, 13 Feb 2004     Volume: 10 Number: 6131

Today's topics:
    Re: API for import? <nobull@mail.com>
    Re: Broken Pipe <matternc@comcast.net>
    Re: Changing Mcdonald to McDonald <tzz@lifelogs.com>
    Re: Forgetting how to use vec (Aaron Sherman)
    Re: Getting CGI to read from a different STDIN source (Bill Gerba)
    Re: Getting CGI to read from a different STDIN source <nobull@mail.com>
    Re: hidden perl <matternc@comcast.net>
    Re: if for... <robw@sofw.org>
    Re: Optimization request (Aaron Sherman)
    Re: parsing out all data between two words with multipl (Anno Siegel)
    Re: parsing out all data between two words with multipl <uri@stemsystems.com>
    Re: parsing out all data between two words with multipl <usenet@morrow.me.uk>
    Re: parsing out all data between two words with multipl <uri@stemsystems.com>
    Re: parsing out all data between two words with multipl (Anno Siegel)
    Re: pattern mattching (Anno Siegel)
    Re: Reading html into a source file (Bill)
    Re: Reading html into a source file <tadmc@augustmail.com>
    Re: Replacing hundreds of hash keys with their values i <nobull@mail.com>
    Re: Subroutines <tadmc@augustmail.com>
    Re: Subroutines (Anno Siegel)
    Re: why do some mail servers treat perl generated mails (Malcolm Dew-Jones)
        Why does "while (<>) { $x .= $_; }  print $x . "\n";" p (Wolfgang)
    Re: Why does "while (<>) { $x .= $_; }  print $x . "\n" <ittyspam@yahoo.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 13 Feb 2004 19:27:51 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: API for import?
Message-Id: <u9d68ikceg.fsf@wcl-l.bham.ac.uk>

kj <nomail@please.com> writes:

> Where can one find good documetation on the API for the import
> function 

When you write your own import() you get to define your own API!

In older versions of Perl you needed to do version checking but
this is now handled by a separate VERSION method.

Old modules' import() still may need keep the legacy version checking
code to support the legacy syntax:

  use Module VERSION, LIST

New modules don't need to worry about this as new code will use one of:

  use Module VERSION LIST
  use Module VERSION

This means you have a completely free hand in your import's API.

> and whatever other information one must know to write
> one's own import function?

You need to know what you want it to do.  You have to supply that
information yourself.

>  (Neither 'perldoc -f import' and pointers
> therein, nor reading the Export.pm source code were particularly
> illuminating on this question.)

I'm not quite sure what "this question" is.  I suspect it doesn't
really exist, you only imagine it does.  Getting answers to questions
whose existanve you are imagining is often very difficult.

That said you may also want to consult:

 perldoc -f use
 perldoc perlmod

The only bit I found unclear was how Perl manages to DWIM for both:

  use Module VERSION
  use Module LIST          [where LIST contains a single element]

From experimentation it seems that if the abiguous argument is a
number literal or a version literal it is seen as VERSION otherwise
it's seen as LIST.  Which seems right from a DWIM standpoint.

If you want to force something that would usually
be treated as a VERSION to be treated as sigle element LIST the
parentheses or a unary plus seem to do the trick.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 13 Feb 2004 14:40:30 -0500
From: Christopher Mattern <matternc@comcast.net>
Subject: Re: Broken Pipe
Message-Id: <aoudnTrwB4yytbDdRVn-jw@comcast.com>

Big and Blue wrote:

> Big and Blue wrote:
>  >
>>   If $filename is large the zcat command may still be pushing the
>> contents into the now deceased head, in which case it will be writing to
>> a closed pipe.  Hence a SIGPIPE is sent.
>> 
>>   Just put:
>> 
>> $SIG{PIPE} = _IGNORE_;
>> 
>> in your code (ideally scoped to the extent of the `` command).
> 
>     Err...could be wrong there.  The "Broken Pipe" message is from the
> shell running the `` command, so a perl SIG handler isn't going to help.
> 
>     So, you'll need to trap the signal in the shell....
> 
>    @temp = `trap "" 13; zcat $filename | head -n50`;

Nope, don't wanna do this.  Once zcat gets the SIGPIPE, you *want*
it to terminate; you don't have any need for the rest of the file,
so why make zcat uncompress it all?  This is actually a bit sticky.
You can get rid of the error message by throwing away stderr:

       @temp = `zcat $filename 2>/dev/null | head -n50`;

but then you won't can't any *other* error messages, either...

>     (Another suggestion would be to install Compress::Zlib and just read
> the first 50 lines entirely in Perl).
> 
This is actually probably the best suggestion.  More efficient and
elegant than anything else I can think of .

          Chris mattern


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

Date: Fri, 13 Feb 2004 14:32:32 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Changing Mcdonald to McDonald
Message-Id: <4noes2hj1r.fsf@collins.bwh.harvard.edu>

On Fri, 13 Feb 2004, usenet@morrow.me.uk wrote:

"porter970" <porter970@lycos.com> wrote:

>> I then capitalize the name using:
>> 
>>     $name =~ s/\b(\w)/\U$1/g;
>> 
>> (which I copied from somewhere and don't fully understand.)
> 
> A simpler way to do it is
>     $name = ucfirst($name);

That's not the same thing.  "de vries" would become "De vries" with
your version, but "De Vries" in porter970's version.

> The problem is essentially insoluble: by uppercasing their names,
> people lose information. There is no way for you to get this info
> back: for instance, consider the case of an inital 'de'. IIRC, some
> people spell it DeFoo and some deFoo (and, indeed, some people are
> called 'Dean' which looks *very* weird as 'DeAn' :)... you have no
> way of knowing which is correct.

This is actually different (as a convention) between the various
European countries, so you could be offending someone a little when
you change "de Anjou" to "De Anjou" (for example).

Also, Japanese names will sometimes be written as "LAST First" to
indicate to a foreign speaker that the LAST name is first in the
string.  Imposing case on that string is almost certainly against the
person's wish.

It's much better to keep the format that people used when they entered
the name, no matter what the format was, and allow the user the option
to change it if they want.  The name is not the primary key in a
database, I hope!

Ted


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

Date: 13 Feb 2004 12:47:00 -0800
From: ajs@ajs.com (Aaron Sherman)
Subject: Re: Forgetting how to use vec
Message-Id: <eaa2c627.0402131247.2ac3482a@posting.google.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<c0gvk4$jh8$2@mamenchi.zrz.TU-Berlin.DE>...
> Darren Dunham  <ddunham@redwood.taos.com> wrote in comp.lang.perl.misc:
> > Aaron Sherman <ajs@ajs.com> wrote:
> > > I think it's time for me to write a module that implements a generic
> > > version of vec (obviously with a different calling convention).
> > 
> > There is already Bit::Vector which may be useful.
> 
> That is a huge powerful module, often the right choice when your problem
> hinges on massive bit manipulation.  For casual use Simon Cozens'
> Bit::Vector::Minimal is an alternative.

Ah, thanks! I had looked at B::V and determined that it was too
heavyweight for what I wanted. I'll look at B:V:M for future efforts.


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

Date: 13 Feb 2004 13:28:30 -0800
From: junkmail@wirespring.com (Bill Gerba)
Subject: Re: Getting CGI to read from a different STDIN source
Message-Id: <7f2e88c6.0402131328.3cdfd83e@posting.google.com>

Well, my problems continue.  According to the docs, when you create a
CGI object using new CGI($FH), the file (or list, or hash, or
whatever) can ONLY contain data in either key=value format or a URI
encoding scheme.  However, in the example below, I'm slurping all of
STDIN into a file, which includes things like the HTTP headers. 
Consequently, when I run the script below, CGI dumps everything into
one huge variable full of crap.

Is it possible to take this entire file and have CGI successfully
parse it out?

A related question is: what's the difference between my $IN filehandle
and the original STDIN when the data is posted to the CGI script?  Is
Apache stripping out the headers or something?

Also, it's worth noting that I'm trying this with a
multipart/form-data HTTP file upload, so there could be different (or
multiple) content-length headers in the POSTed data.

Here's the code:

#!/usr/bin/perl -w
use strict;
use Data::Dumper;
use CGI;

# First, grab the HTTP POST stream and dump it into a file.
my ($TMP,$DATA);
open($TMP,">","posted_data.txt") or die "can't open posted_data file:
$!";
while (read STDIN, $DATA, 1024) {
    print $TMP $DATA;
}
close $TMP;

# Make a CGI object taking data from a filehandle $IN
my $IN;
open($IN,"posted_data.txt") or die "can't open temp file: $!";

# Print out the data from the HTTP POST as CGI sees it.
my $cc = new CGI($IN);
my %v = $cc->Vars;
print $cc->header();
print Dumper(\%v);

exit(0);


If you want to try this yourself, here's the HTML form that I'm using
to submit to the CGI:


<HTML>
<HEAD>
<TITLE>FireCast ClientCenter : Upload Files</TITLE>
</HEAD>
<BODY>
<form enctype="multipart/form-data" action="/cgi-bin/uptest.pl"
method="POST">

<table border=0 align="left" cellpadding=3>
  <tr><td><input type="file" name="upfile1"></td></tr>
  <tr><td><input type="file" name="upfile2"></td></tr>
  <tr>
    <td colspan=2 align="center">
      <input type="hidden" name="sessionid" value="1234">
      <input type='hidden' name='mode' value='upload'>
      <input type="submit" value="Upload">
    </td>
  </tr>
</table>
</form>
</BODY>
</HTML>



Thanks again!


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

Date: 13 Feb 2004 22:11:24 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Getting CGI to read from a different STDIN source
Message-Id: <u9r7wyiq9f.fsf@wcl-l.bham.ac.uk>

junkmail@wirespring.com (Bill Gerba) writes:

> Well, my problems continue.  According to the docs, when you create a
> CGI object using new CGI($FH), the file (or list, or hash, or
> whatever) can ONLY contain data in either key=value format or a URI
> encoding scheme.  However, in the example below, I'm slurping all of
> STDIN into a file, which includes things like the HTTP headers. 
> Consequently, when I run the script below, CGI dumps everything into
> one huge variable full of crap.
> 
> Is it possible to take this entire file and have CGI successfully
> parse it out?

You could just open the file as STDIN

> A related question is: what's the difference between my $IN filehandle
> and the original STDIN when the data is posted to the CGI script?

The orginal STDIN is the speical standard input file handle.

> my $IN;
> open($IN,"posted_data.txt") or die "can't open temp file: $!";
> 
> # Print out the data from the HTTP POST as CGI sees it.
> my $cc = new CGI($IN);

How about

  # Untested
  open(STDIN,"posted_data.txt") or die "can't open temp file: $!";
  my $cc = new CGI;

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 13 Feb 2004 15:33:16 -0500
From: Christopher Mattern <matternc@comcast.net>
Subject: Re: hidden perl
Message-Id: <avmdnbgncOcQqbDdRVn-uw@comcast.com>

daniel caplan wrote:

> sorry if this is in the wrong newsgroup.  am not a perl programmer, so am
> not sure under what heading to put this under.  simply put:
> 
> my company has a software (written in perl) that it runs on our internal
> servers (linux).  we would
> like to be able to have 3rd party companies run it, not off of our
> servers,
> but on their own internals network.  but obviously we don't want them to
> be able to see our source code.
> 
"Obviously"?  You may have some reasons for hiding your source code, but
nothing you've said here makes a need to do so particularly obvious.

> can i ask what solutions there are?

No good ones.
> 
> are there compilers?

Yes.

> reliable ones?

No.

>  am sure we are not the first to
> encounter this scenario, so am sure there is a solution.

Frankly, the authors of Perl are believers in open source; the
source code of Perl itself is openly and freely available to
anyone who wishes to study or modify it.  Source code obfuscation
is not particularly important to them.

            Chris Mattern



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

Date: Fri, 13 Feb 2004 14:22:25 -0500
From: Robert Wallace <robw@sofw.org>
Subject: Re: if for...
Message-Id: <402D23F1.1B05D2A0@sofw.org>



Aaron Sherman wrote:
> 
> Brian McCauley <nobull@mail.com> wrote:
> 
> > I think you really meant to ask why can't I say:
> >
> >   .... if m/str/ for @arr;
> [...]
> > All I can find are:
> >
 .......

> >
> > You'll note that [1] and [4] are no sort of explaintion. [2] applies
> > to pretty much everyting in Perl.  [3] is an argument against the
> > "for" statement modifier per-se, not an argument against being able to
> > chain statement modifiers.
> 
> Ok, so here are some more:
 ..........
> So, you have to restrict for to a single instance, and that seems
> non-intuitive to many users, so you really haven't gained much clarity
> in the language.



wow, you guys paint such a dark picture.


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

Date: 13 Feb 2004 12:45:46 -0800
From: ajs@ajs.com (Aaron Sherman)
Subject: Re: Optimization request
Message-Id: <eaa2c627.0402131245.688cbde6@posting.google.com>

"David K. Wall" <dwall@fastmail.fm> wrote:

> The reason I responded to your post is because it seemed (and seems) to 
> criticize me and not my answer to the OP. I guess I tried too hard to be 
> polite and didn't make that point. 

If you heard me criticize YOU at any point, please quote it. I really
don't know you, so I don't have anything to criticize. Stick to the
topic at hand, please. The topic was requests for performance
information, not infighting.

My distinction was on the difference between "which is faster" and
"which would you expect to be faster". That's all. Nothing personal.

> Just drop it, ok? You convinced me the first time, I don't need yet another 
> sermon.

Ah, the old "this is the last word, so don't reply!" ;-)


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

Date: 13 Feb 2004 20:17:38 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: parsing out all data between two words with multiple instances in a file.
Message-Id: <c0jbd2$66d$2@mamenchi.zrz.TU-Berlin.DE>

Ben Morrow  <usenet@morrow.me.uk> wrote in comp.lang.perl.misc:
> 
> kprunell@microsoft.com (KP) wrote:
> > my $file;
> > my $fileinfo;
> > 
> > open (FILE, $FileHandle) || die;
> 
> Put $! and the name of the file in the error message.
> 
> >   while ($file = <FILE> )
> 
> This reads FILE a line at a time. This means you will get at most one
> of your <pre> tags at once... so it isn't going to work.
> 
> >   {
> >     if ($file =~ /.*<junk>.*/)
> >     {
> >       while ($fileinfo = <FILE>)
> >       {
> >         if ($fileinfo =~ /.*<pre>(.*)<\/pre>)
> >         {
> >           $FileList = $FileList .';'. $1;
> >         }
> >       }last;
> >     }
> >   }
> > print $FileList;
> 
> You want something more like (untested):
> 
> my $semi;
> while (<FILE>) {
> 
>     if (/<pre>/ .. m|</pre>|) {
>         if ($semi) {
>             print ";\n";
>             undef $semi;
>         }
>         print;
>     }
> 
>     $semi = m|</pre>|;
> }
> 
> Hmmm... I feel it should be possible to make than more elegant. Ah
> well.

Well, for one it prints the delimiting "<pre>" and "</pre>", which
is unwanted.

If the ";" lines are allowed to follow every block (instead of appearing
only between blocks), there is no need for an auxiliary variable.  So
I'd rewrite your solution like this:

    my $from = qr/<pre>/;
    my $to = qr|</pre>|;

    while ( <FILE> ) {
        if ( /$from/ .. /$to/ ) {
            print unless /$from/ or /$to/;
            print ";\n" if /$to/;
        }
    }

Or

    /$from/ .. /$to/ and (/$from/ or print /$to/ ? ";\n" : $_) while <FILE>;

:)

Anno



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

Date: Fri, 13 Feb 2004 22:04:39 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: parsing out all data between two words with multiple instances in a file.
Message-Id: <x74qtuws94.fsf@mail.sysarch.com>

>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:

  AS>     my $from = qr/<pre>/;
  AS>     my $to = qr|</pre>|;

  AS>     while ( <FILE> ) {
  AS>         if ( /$from/ .. /$to/ ) {
  AS>             print unless /$from/ or /$to/;
  AS>             print ";\n" if /$to/;
  AS>         }
  AS>     }

bah!! how many of you have ever seen or used the RETURN value from
scalar range?

    while ( <FILE> ) {
        if ( my $range = /$from/ .. /$to/ ) {
            print ";\n" and next if $range == 1 ;
            print unless $range =~ /e/i ;
        }
    }

you can then put the regexes back in the .. line as you don't need them
again.

    while ( <FILE> ) {
        if ( my $range = /<pre>/ .. m|</pre>|) {
            print ";\n" and next if $range == 1 ;
            print unless $range =~ /e/i ;
        }
    }

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Fri, 13 Feb 2004 22:08:10 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: parsing out all data between two words with multiple instances in a file.
Message-Id: <c0jhsa$e1a$1@wisteria.csv.warwick.ac.uk>


Uri Guttman <uri@stemsystems.com> wrote:
>     while ( <FILE> ) {
>         if ( my $range = /<pre>/ .. m|</pre>|) {
>             print ";\n" and next if $range == 1 ;
>             print unless $range =~ /e/i ;
>         }
>     }

Ah... thank you! I had just been reading about the return of .., and
was sure it could be used here... this prints an extra semi at the
start though.

Ben

-- 
And if you wanna make sense / Whatcha looking at me for?          (Fiona Apple)
                            * ben@morrow.me.uk *


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

Date: Fri, 13 Feb 2004 22:14:02 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: parsing out all data between two words with multiple instances in a file.
Message-Id: <x7wu6qvd91.fsf@mail.sysarch.com>

>>>>> "BM" == Ben Morrow <usenet@morrow.me.uk> writes:

  BM> Uri Guttman <uri@stemsystems.com> wrote:
  >> while ( <FILE> ) {
  >> if ( my $range = /<pre>/ .. m|</pre>|) {
  >> print ";\n" and next if $range == 1 ;
  >> print unless $range =~ /e/i ;
  >> }
  >> }

  BM> Ah... thank you! I had just been reading about the return of .., and
  BM> was sure it could be used here... this prints an extra semi at the
  BM> start though.

i wasn't sure of the requirements and i didn't check carefully. i just
wanted to show the use of the range value. it is dreadfully under
utilized. i have written many line by line parsers with similar logic.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 13 Feb 2004 22:16:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: parsing out all data between two words with multiple instances in a file.
Message-Id: <c0jicn$9cm$1@mamenchi.zrz.TU-Berlin.DE>

Uri Guttman  <uri@stemsystems.com> wrote in comp.lang.perl.misc:
> >>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
> 
>   AS>     my $from = qr/<pre>/;
>   AS>     my $to = qr|</pre>|;
> 
>   AS>     while ( <FILE> ) {
>   AS>         if ( /$from/ .. /$to/ ) {
>   AS>             print unless /$from/ or /$to/;
>   AS>             print ";\n" if /$to/;
>   AS>         }
>   AS>     }
> 
> bah!! how many of you have ever seen or used the RETURN value from
> scalar range?
> 
>     while ( <FILE> ) {
>         if ( my $range = /<pre>/ .. m|</pre>|) {
>             print ";\n" and next if $range == 1 ;
>             print unless $range =~ /e/i ;
>         }
>     }

Now you mention it, yes, there's that behavior, obviously meant to
cover cases like this.

".." is a bit like "split" in that it has a lot of special cases and
DWIMish behavior, to a degree that makes it hard to keep up with
everything.  Thanks for pointing it out.

Anno


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

Date: 13 Feb 2004 19:25:59 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: pattern mattching
Message-Id: <c0j8c7$3ba$1@mamenchi.zrz.TU-Berlin.DE>

Pascal <p805@yahoo.com> wrote in comp.lang.perl.misc:
> I'm try to match a pattern which doesn't really work for me kuz I just
> want the pattern to appear once for example I have this line:
> 
> int x=0;x<=100;x++
> 
> I only what this: =, <=, ++
> but I get all of these: =,<,=,<=,+,+,++

So what pattern are you using?

> because In an other line I could have this: y=x+y then I would like to
> have:=,+

Looks like you're after the operators in C code.  If so, why don't
you say so?

> but I can't seem to figure out what pattern to use That would work for
> all situation.

What are "all" situations?

If my assumption is right that you want to parse C code for operators,
pattern matching won't do.  You'll need a parser.  Your best best is
probably Parse::RecDescent.  There may even be (partial) C parsers
on CPAN.

Anno


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

Date: 13 Feb 2004 11:34:14 -0800
From: wherrera@lynxview.com (Bill)
Subject: Re: Reading html into a source file
Message-Id: <239ce42f.0402131134.56480af2@posting.google.com>

chris.tunnecliff@markelintl.com (Chris) wrote in message news:<b8146f1.0402130640.4ea9625@posting.google.com>...

> #!/usr/local/bin/perl
> print "Content-Type: text/plain\n\n";
> use LWP::Simple;
> $content = get ("http://www.webbuyeruk.co.uk/index.htm");
> print " This is Content:\n\n $content \n\n";
> exit;
> 
> (above as seen in google postings) but no contents appear on my
> screen?  Any help appreciated!  I'm using perl 5.8 on windows 2K.

Works here, 5.8, XP.  are you running it via

c:> perl filename.pl

or as 

c:> filename.pl  

or by clickin on filename?  If the latter two, you need
/usr/local/bin/perl.exe to exist, of course :/


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

Date: Fri, 13 Feb 2004 16:19:19 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Reading html into a source file
Message-Id: <slrnc2qjb7.1l3.tadmc@magna.augustmail.com>

Chris <chris.tunnecliff@markelintl.com> wrote:

> Apologies for the mail 


What mail?


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


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

Date: 13 Feb 2004 19:52:20 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Replacing hundreds of hash keys with their values in a text document
Message-Id: <u94qtukb9n.fsf@wcl-l.bham.ac.uk>

Arvin Portlock <apollock11@hotmail.com> writes:

> > If your %characters doesn't include all the non-ascii in the file, you
> > could use
> >
> >     my $to_encode = '[' . (join '', keys %characters) . ']';
> >     while (<$FILE>) {
> >         s/($to_encode)/$characters{$1}/g;
> >         print;
> >     }
> >
> > Ben
> 
> 
> That makes MUCH more sense and is just what I'll do.

I've not benchmarked it but I suspect it would be more efficient to
take the appending of the () outsie the loop.  I'd also explicitly
precompile the regex - although I think Perl will actually manage to
avoid unnecessary recompilation anyhow.

     my $to_encode = join '', keys %characters;
     $to_encode = qr/([$to_encode])/;
     while (<$FILE>) {
         s/$to_encode/$characters{$1}/g;
         print;
     }

Note: Some people would use @{[]} interpolation here but although I'm
a proponent of @{[]} in here-docs I think it looks messy in qr//.

     my $to_encode = qr/([@{[ join '', keys %characters ]}])/;

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 13 Feb 2004 16:38:17 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Subroutines
Message-Id: <slrnc2qkep.1l3.tadmc@magna.augustmail.com>

Ondra <neufingero@quick.cz> wrote:

> I would like to know what is do the code below:


I will assume your interest is as a learning exercise, because
it is amateurish and crufty code, I wouldn't trust it.


> sub safe {
>     
>     my $url = shift;
>     
>     return 1 if ($url =~ /^(javascript|mailto):/is);


I lose confidence in a programmer when they throw do-nothing
options on willy-nilly. The //s does nothing when used with
that pattern, so it should not be there.

Whoever wrote this didn't really understand what they were doing.


>     for (@safe) {   #*******I cann't understand this


It does the same as these:

   for $_ (@safe)
   foreach  (@safe)
   foreach $_ (@safe)


See the "Foreach Loops" section in perlsyn.pod.


> 	return 1 if ($url =~ /\w+:\/\/((\w|-)+\.)*$_/is);


//s does nothing yet again. 

//i doesn't do anything either!


>     }
>     return 0;
>     
> }


It appears that @safe holds "approved" TLDs or something. The code
attempts to return true for those domains.

It does it badly. If @safe contains "com", it will match (return true)
when $url = "http://www.company" ...
   
Send that code to the bit bucket, where it belongs.


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


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

Date: 13 Feb 2004 22:54:22 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Subroutines
Message-Id: <c0jkiu$9cm$2@mamenchi.zrz.TU-Berlin.DE>

Tad McClellan  <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
> Ondra <neufingero@quick.cz> wrote:
> 
> > I would like to know what is do the code below:
> 
> 
> I will assume your interest is as a learning exercise, because
> it is amateurish and crufty code, I wouldn't trust it.

[...]

> > 	return 1 if ($url =~ /\w+:\/\/((\w|-)+\.)*$_/is);
> 
> 
> //s does nothing yet again. 
> 
> //i doesn't do anything either!

I completely agree with your overall assessment, but /i may do something
here, depending on $_.

Anno


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

Date: 13 Feb 2004 12:18:24 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: why do some mail servers treat perl generated mails as Bulk
Message-Id: <402d3110@news.victoria.tc.ca>

KK (kewlkarun@yahoo.com) wrote:
: Hi,
:   With Mail::Sender I could finally able to send mails from windows
: machine. However, when I use yahoo DSL HMTP mail server, my mails are
: considered Bulk Emails. Is there a way I can avoid this ?

Apparently not if you send from your PC using your current provider.

Yahoo is probably looking at your ip address.  Many many many addresses
are in untrusted ranges and will be flagged or simply discarded by many
systems that receive mail.

To send mail reliably, you need to find a host that is trusted by systems
that receive mail and send your mail from that host.  Depending on the
host, you may be able to send mail from your PC using smtp but will point
the smtp at your ISP's mail host and use it as a relay, so the recipients
see the trusted host's ip.

I'm not saying this is technically required, or good or bad, I'm just
saying that that is often what you must do in practise if you wish to
upload your message data into the reciepients file space.

:   Peon, just curious as to why cant I use these modules to post mails
: to employers? 

He said don't _spam_ employers using these modules.  You could use them to
send other mail to employers.  Beware though that sending multiple copies
of similar documents to anyone is liable to put your mail and/or ip
address into various spammer lists.

: would they be detecting them as spam? if yes, how? 

E.g. DCC, RAZOR

: what
: is the best way to mail the same mail to 10 different people? 

10 copies is bulk, no? so you'll notice the yahoo bulk flag would have 
been correct in this case.

I doubt that ten copies would get you onto any/many spam lists, though it
might.  Unless you have a pre-existing permission to send mail then the
best thing is to tailor each mail to the specific requirements of the
recipient so that the mail is truly "on topic" for the receipient when
they read it.  Remember though that what a sender considers "on topic"  
is commonly just "the usual crap" to many of the recipients.

: After all, programming should be practical!

rejecting/flagging mail from untrusted ip's is very practical - from the 
recipient's point of view.




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

Date: Fri, 13 Feb 2004 19:38:28 GMT
From: Mott@nospam.UNM.edu (Wolfgang)
Subject: Why does "while (<>) { $x .= $_; }  print $x . "\n";" print all input lines?
Message-Id: <402d2677.12148047@nntp.ucsb.edu>

Being familiar with other programming languages, I had assumed that
only the very last input line would be printed by the code below.  I
was thinking that because the print statement is outside the 'while'
loop.

$x = "";
while (<>) {
    $x .= $_;
}
print $x . "\n";

Why does this code print all input lines?

Thanks, 
Wolfgang


while (<>) { $x .= $_; }  print $x . "\n";



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

Date: Fri, 13 Feb 2004 14:51:25 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Why does "while (<>) { $x .= $_; }  print $x . "\n";" print all input lines?
Message-Id: <20040213144953.S23965@dishwasher.cs.rpi.edu>

On Fri, 13 Feb 2004, Wolfgang wrote:

> Being familiar with other programming languages, I had assumed that
> only the very last input line would be printed by the code below.  I
> was thinking that because the print statement is outside the 'while'
> loop.
>
> $x = "";
> while (<>) {
>     $x .= $_;
> }
> print $x . "\n";
>
> Why does this code print all input lines?
>
> Thanks,
> Wolfgang
>
>
> while (<>) { $x .= $_; }  print $x . "\n";
>
>

Because you're concatenating $x with the next line from the input file
each time through the loop.  .= is the 'concatenate and assign' operator.
It takes whatever was previously in $x, and adds $_ onto the end of it.
Therefore, when you print $x at the end, it contains all lines from the
file.

Paul Lalli


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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