[25150] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7399 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 12 18:05:45 2004

Date: Fri, 12 Nov 2004 15:05:08 -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, 12 Nov 2004     Volume: 10 Number: 7399

Today's topics:
    Re: \$:xml-ms\{((([a-zA-Z_]+\w*)+(\.([a-zA-Z_]+\w*))+){ <vijai.lists@gmail.com>
    Re: \$:xml-ms\{((([a-zA-Z_]+\w*)+(\.([a-zA-Z_]+\w*))+){ <vijai.lists@gmail.com>
    Re: backreferneces in search pattern <responder_solo_en_el_grupo@yahoo.es>
    Re: backreferneces in search pattern <jgibson@mail.arc.nasa.gov>
        FAQ 4.5: How do I convert between numeric representatio <comdog@panix.com>
    Re: Fun problem: Overlapping words <bigj@kamelfreund.de>
    Re: Need perl+java programmer <postmaster@castleamber.com>
    Re: Perl golf: lowercasing all path names (A. Farber)
    Re: Perl golf: lowercasing all path names <jurgenex@hotmail.com>
    Re: PERL+CGI+PLUG-IN architecture <colo@megapolis.pl>
        Re:backreferneces in search pattern <mstep@t-online.de>
    Re: replace pattern including newline : perl version 5. <someone@example.com>
    Re: Script to pass info to GET string <dha@panix.com>
    Re: simple perl script for automatic form submission. <ioneabu@yahoo.com>
    Re: simple perl script for automatic form submission. <jgibson@mail.arc.nasa.gov>
        syntax problem (Mostafa)
    Re: Two operations with one last if? <dwall@fastmail.fm>
    Re: Two operations with one last if? <uguttman@athenahealth.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 12 Nov 2004 16:43:46 -0600
From: Vijayaraghavan Kalyanapasupathy <vijai.lists@gmail.com>
Subject: Re: \$:xml-ms\{((([a-zA-Z_]+\w*)+(\.([a-zA-Z_]+\w*))+){1,1} | (\$environment\{"([a-zA-Z_]+\w*)+(\.([a-zA-Z_]+\w*))+"\}){1,1})\}
Message-Id: <MPG.1bfef89deff7234e989693@news.vanderbilt.edu>

In article <yzd654be7dd.fsf@invalid.net>, do-not-use@invalid.net says...

> 
> In the above expression, you have spaces around the '|' character.
> That means that spaces have to be present in the string in order for
> the expression to match.
> 
> Simple example: /abc | def/ matches "abc " and it matches " def", but
> not "abc" or "def".  /abc|def/ does match both "abc" and "def".
> So maybe the solution is to remove those spaces.
>

Aha! I see. I should have read the manual more closely perhaps. Thanks 
for pointing it out. It does work now!

-vijai.


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

Date: Fri, 12 Nov 2004 16:45:24 -0600
From: Vijayaraghavan Kalyanapasupathy <vijai.lists@gmail.com>
Subject: Re: \$:xml-ms\{((([a-zA-Z_]+\w*)+(\.([a-zA-Z_]+\w*))+){1,1} | (\$environment\{"([a-zA-Z_]+\w*)+(\.([a-zA-Z_]+\w*))+"\}){1,1})\}
Message-Id: <MPG.1bfef8f4fef60e3c989694@news.vanderbilt.edu>

In article <cn24b9$m71$1@mamenchi.zrz.TU-Berlin.DE>, anno4000
@lublin.zrz.tu-berlin.de says...

Yes, you are correct. I should split up the matching!

thank you,

-vijai.


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

Date: Fri, 12 Nov 2004 21:49:03 +0000 (UTC)
From: Hue-Bond <responder_solo_en_el_grupo@yahoo.es>
Subject: Re: backreferneces in search pattern
Message-Id: <cn3b4f$ci3$1@cernicalo.emeteo.local>

Marek Stepanek, Fri20041112@20:42:43(CET):
>
> while (<>) {
>     my @results = 
> m!onmouseover="[^']+'([^']+)'(?:(?:(?:;\s+[^']+)'([^']+)')+)?(?:(?:[^']+)'([
> ^']+)')?"!g;
>     foreach $i (0..$#results) {
>         print "'", $i, "',\n";
>         }
> }
>
> but this gives me a funny result :
>
> '0',
> '1',
> '2',

I think you want to print $results[$i] instead.


-- 
 Hue-Bond


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

Date: Fri, 12 Nov 2004 13:51:46 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: backreferneces in search pattern
Message-Id: <121120041351468152%jgibson@mail.arc.nasa.gov>

In article <BDBAD0C3.BAE7%mstep@t-online.de>, Marek Stepanek
<mstep@t-online.de> wrote:


> use strict;
> use warnings;
> 
> 
> while (<>) {
>     my @results = 
> m!onmouseover="[^']+'([^']+)'(?:(?:(?:;\s+[^']+)'([^']+)')+)?(?:(?:[^']+)'([
> ^']+)')?"!g;
>     foreach $i (0..$#results) {
>         print "'", $i, "',\n";


         print "'$results[$i]'.\n";


>         }
> }


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

Date: Fri, 12 Nov 2004 23:03:02 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 4.5: How do I convert between numeric representations/bases/radixes?
Message-Id: <cn3ff6$n3u$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

4.5: How do I convert between numeric representations/bases/radixes?

    As always with Perl there is more than one way to do it. Below are a few
    examples of approaches to making common conversions between number
    representations. This is intended to be representational rather than
    exhaustive.

    Some of the examples below use the Bit::Vector module from CPAN. The
    reason you might choose Bit::Vector over the perl built in functions is
    that it works with numbers of ANY size, that it is optimized for speed
    on some operations, and for at least some programmers the notation might
    be familiar.

    How do I convert hexadecimal into decimal
        Using perl's built in conversion of 0x notation:

            $dec = 0xDEADBEEF;

        Using the hex function:

            $dec = hex("DEADBEEF");

        Using pack:

            $dec = unpack("N", pack("H8", substr("0" x 8 . "DEADBEEF", -8)));

        Using the CPAN module Bit::Vector:

            use Bit::Vector;
            $vec = Bit::Vector->new_Hex(32, "DEADBEEF");
            $dec = $vec->to_Dec();

    How do I convert from decimal to hexadecimal
        Using sprintf:

            $hex = sprintf("%X", 3735928559); # upper case A-F
            $hex = sprintf("%x", 3735928559); # lower case a-f

        Using unpack:

            $hex = unpack("H*", pack("N", 3735928559));

        Using Bit::Vector:

            use Bit::Vector;
            $vec = Bit::Vector->new_Dec(32, -559038737);
            $hex = $vec->to_Hex();

        And Bit::Vector supports odd bit counts:

            use Bit::Vector;
            $vec = Bit::Vector->new_Dec(33, 3735928559);
            $vec->Resize(32); # suppress leading 0 if unwanted
            $hex = $vec->to_Hex();

    How do I convert from octal to decimal
        Using Perl's built in conversion of numbers with leading zeros:

            $dec = 033653337357; # note the leading 0!

        Using the oct function:

            $dec = oct("33653337357");

        Using Bit::Vector:

            use Bit::Vector;
            $vec = Bit::Vector->new(32);
            $vec->Chunk_List_Store(3, split(//, reverse "33653337357"));
            $dec = $vec->to_Dec();

    How do I convert from decimal to octal
        Using sprintf:

            $oct = sprintf("%o", 3735928559);

        Using Bit::Vector:

            use Bit::Vector;
            $vec = Bit::Vector->new_Dec(32, -559038737);
            $oct = reverse join('', $vec->Chunk_List_Read(3));

    How do I convert from binary to decimal
        Perl 5.6 lets you write binary numbers directly with the 0b
        notation:

            $number = 0b10110110;

        Using oct:

            my $input = "10110110";
            $decimal = oct( "0b$input" );

        Using pack and ord:

            $decimal = ord(pack('B8', '10110110'));

        Using pack and unpack for larger strings:

            $int = unpack("N", pack("B32",
                substr("0" x 32 . "11110101011011011111011101111", -32)));
            $dec = sprintf("%d", $int);

            # substr() is used to left pad a 32 character string with zeros.

        Using Bit::Vector:

            $vec = Bit::Vector->new_Bin(32, "11011110101011011011111011101111");
            $dec = $vec->to_Dec();

    How do I convert from decimal to binary
        Using sprintf (perl 5.6+):

            $bin = sprintf("%b", 3735928559);

        Using unpack:

            $bin = unpack("B*", pack("N", 3735928559));

        Using Bit::Vector:

            use Bit::Vector;
            $vec = Bit::Vector->new_Dec(32, -559038737);
            $bin = $vec->to_Bin();

        The remaining transformations (e.g. hex -> oct, bin -> hex, etc.)
        are left as an exercise to the inclined reader.



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: Fri, 12 Nov 2004 21:00:31 +0100
From: Janek Schleicher <bigj@kamelfreund.de>
Subject: Re: Fun problem: Overlapping words
Message-Id: <pan.2004.11.12.20.00.30.254435@kamelfreund.de>

On Fri, 12 Nov 2004 17:12:22 +0000, Stuart Moore wrote:

> I was chatting with some friends, and we were trying to work out suitable
> strings of letters which could have spaces and punctuation in different
> places to produce different sentences
> 
> e.g.
> 
> Therestopenlarge
> 
> parses to
> 
> There stop enlarge
> or
> The rest open large

It might be only a beginning, but the following snippet finds at least one
of these solutions at my system:

#!/usr/bin/perl

use strict;
use warnings;

open WORDS,'<','/usr/share/dict/american-english' or die "Can't open word list";
chomp( my @word = sort {- (length($a) <=> length($b))} (<WORDS>) );
close WORDS;

my $string = 'Therestopenlarge';

foreach (grep $_, @word) {
	$string =~ s/(\A[^{]*|\}[^{]*)($_)/$1\{$2\}/gsi;
}

$string =~ tr/}{/ /d;

print $string;


Of course this snippet isn't very optimized (but for at least quick
written), and it prefers to find long words instead of short words.

(An idea to find alternative solutions might be to remove brackets around
some (or all) words after finding a solution und restart the algorithm
without an already found word, so it has to find another solution - but in
my opinion it's your problem to do it as it is also your problem :-))


Greetings,
Janek


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

Date: 12 Nov 2004 20:51:55 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Need perl+java programmer
Message-Id: <Xns959F97378CBF0castleamber@130.133.1.4>

Uri Guttman wrote:

>>>>>> "JB" == John Bokma <postmaster@castleamber.com> writes:
> 
>   JB> Laura wrote:
>  >> How did you ever get your Perl patform embedded in Java?  What
>  >> kind of a crazy scheme was that?  I would recommend hiring a Java
>  >> and a Perl programmer for this job because Perl is a left-brain
>  >> language while Java is right-brain.  You are not likely to find
>  >> someone actively at the top of their abilities in both languages.
> 
>   JB> Odd. I try to be that :-)
> 
> she is amazed when anyone can be at the top in any language, given her
> skill set.  

Ah ok. Well I am certainly not at the top of any language, I doubt anyone 
can really know all ins and outs of a language. I learn quite often new 
tricks here ;-) And I use Perl for over 10 years now.

-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


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

Date: 12 Nov 2004 13:18:35 -0800
From: Alexander.Farber@t-online.de (A. Farber)
Subject: Re: Perl golf: lowercasing all path names
Message-Id: <c9ccaf83.0411121318.3a046a4b@posting.google.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<cn2du5$sar$1@mamenchi.zrz.TU-Berlin.DE>...
> A. Farber <Alexander.Farber@t-online.de> wrote in comp.lang.perl.misc:
> > I need to lowercase all files and directories in the current
> > directory on Linux and have come up with the following script:
> 
> IOW, use File::Find (or the newer File::Find::Rule, which I haven't
> looked at) to gather the file names.  Use Perl's rename() to do the
> renaming (and check for success instead of making a guess with -e).
> That way you won't have to worry about escaping weird path names
> because no shell tries to interpret them.  It won't make the
> script shorter, but it will make it correcter.

Won't rename() call sh and thus be slower than just 
printing a batch of mv-commands to one single sh?

BTW I've noticed that checking with -e in the perl part
won't work because of buffering and have to use "test -e"
(which makes it all uglier):

find . -depth -print0 | perl -n0e '
        s,([`"\$\\]),\\$1,g;

        $old = $_; 
        s,([^/]+)$,\L$1,;
        next if $old eq $_;

        print qq{
                if test -e "$_"; then
                        echo "Can not move $old to $_: $_ exists already"
                        exit 1
                else
                        mv -v "$old" "$_"
                fi
        }' | sh

I still think it's a legal perl problem. If someone has 
a better solution with File::Find, I'd like to see it

Regards
Alex


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

Date: Fri, 12 Nov 2004 22:09:18 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Perl golf: lowercasing all path names
Message-Id: <iwald.62$pP5.24@trnddc05>

A. Farber wrote:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
>> A. Farber <Alexander.Farber@t-online.de> wrote in
>>> I need to lowercase all files and directories in the current
>>> directory on Linux and have come up with the following script:
>
> Won't rename() call sh and thus be slower than just

I haven't seen the implementation of rename() but why do believe it would 
shell out?
That would be a very odd thing to do.

> printing a batch of mv-commands to one single sh?
>
> BTW I've noticed that checking with -e in the perl part
> won't work because of buffering and have to use "test -e"

What buffering? rename() doesn't do any buffering.

> (which makes it all uglier):
>
> find . -depth -print0 | perl -n0e '
>        s,([`"\$\\]),\\$1,g;
>
>        $old = $_;
>        s,([^/]+)$,\L$1,;
>        next if $old eq $_;
>
>        print qq{
>                if test -e "$_"; then
>                        echo "Can not move $old to $_: $_ exists
>                        already" exit 1
>                else
>                        mv -v "$old" "$_"
>                fi
>        }' | sh

Aaargggg!! What a concept! Using find(1) to call a perl script to create a 
shell script to pipe to sh. I wonder if there is a more convoluted way.

> I still think it's a legal perl problem.

Well, kind of. Strictly speaking it's more about getting your ducks in a row 
then about a Perl problem. You could program this more elegantly in any 
programming language.

> If someone has
> a better solution with File::Find, I'd like to see it

Guess you have missed my earlier post, then.

jue 




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

Date: Fri, 12 Nov 2004 23:59:52 +0000
From: Colombo <colo@megapolis.pl>
Subject: Re: PERL+CGI+PLUG-IN architecture
Message-Id: <cn3f1m$7tm$1@achot.icm.edu.pl>

Jürgen Exner wrote:
> Colombo wrote:
> 
>>Colombo wrote:
>>
>>>I'm looking for any information (or example programs) about writing
>>>programs in perl (cgi) in plug-in architecture. I was searching
>>>almost everywhere with no result :(.
>>
>>In other way, I'm looking for mechanism in perl to load and use new
>>modules while running program.
>>I hope this is clear because I don't know how to explain it in other
>>way.
> 
> 
> Ah, ok, why didnt' you say so in the first place?
> 
> Most likely you are looking for
>     perldoc -f require
> but you should also check
>     perldoc -f do
>     perldoc -f eval
> 
> jue 
> 

Thanks. I read it and I will try to make it somehow. Maybe you know if
there is any module that makes it easier? I mean some automatic loading
modules?

Colombo


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

Date: Fri, 12 Nov 2004 20:42:43 +0100
From: Marek Stepanek <mstep@t-online.de>
Subject: Re:backreferneces in search pattern
Message-Id: <BDBAD0C3.BAE7%mstep@t-online.de>

thank you Bob for this long, patient and pedagogic reply :-)


On 12/11/2004 04:49, in article 41943063_1@127.0.0.1, "Bob Walton"
<see@sig.invalid> wrote:

> Marek Stepanek wrote:
> ...
> 
>> I try to set up a Perl-Filter (for BBEdit on Macintosh). I want to match and
>> print out all gifs needed for a rollover in an HTML-File. The filter should
> 
> Unless you control the layout of the HTML, you would be much better off
> to parse your HTML using a HTML parser module (HTML::Parser, perhaps).
> Correctly parsing HTML is much harder than it appears at first glance.
> 

I just installed HTML::Parser, but before learning to use it, I would like
to learn my Perl first. And this Module would not function as a filter (in
BBEdit), isn't it ? And I think my regex was right, to extract my rollover
gifs, I was searching for, or am I wrong ?



>> 
>> #!/usr/bin/perl -w
>> 
> You are missing:
> 
>     use strict;
>     use warnings;
> 
> Let Perl help you all it can.  I see you did use the -w switch -- but
> these days it is better to
> 
>     use warnings;
> 
> because of the additional control over the warnings it affords.  See
> below for what I am talking about.
> 

Thank you ! I thought the -w switch would do the same as "use warnings". The
"use strict" I should put systematically specially as a beginner ! ( bad
conscience :)

>> 
>> while (<>) {
>>     ($1, $2, $3) =
> -------^^--^^--^^
> 
> Those are your readonly variables that you are attempting to modify.  See
> 
>     perldoc perlvar
> 
> particularly the section about $<digits> .  Note that the $1, $2, etc
> variables are assigned by simply placing capturing sets of parentheses
> in a regular expression.  Judging from your next couple of lines of
> code, you probably want:
> 
>     my @results =
> 
> on this line, and then remove the "my @results=($1,$2,$3);" line.

like that ? :

#!/usr/bin/perl -w


use strict;
use warnings;


while (<>) {
    my @results = 
m!onmouseover="[^']+'([^']+)'(?:(?:(?:;\s+[^']+)'([^']+)')+)?(?:(?:[^']+)'([
^']+)')?"!g;
    foreach $i (0..$#results) {
        print "'", $i, "',\n";
        }
}

but this gives me a funny result :

'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'10',
'11', etc etc


I suppose there is something wrong with "scalar context" and the array
@results ... I would be very grateful, if somebody could correct this
version above !


greetings from Munich


marek




-- 
______________________________________________________________________
___PODIUM_INTERNATIONAL_//_the_embassy_for_talented_young_musicians___
_______Marek_Stepanek__mstep_[at]_PodiumInternational_[dot]_org_______
__________________http://www.PodiumInternational.org__________________
______________________________________________________________________








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

Date: Fri, 12 Nov 2004 21:40:10 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: replace pattern including newline : perl version 5.8
Message-Id: <_4ald.149209$df2.118815@edtnps89>

Prince wrote:
> 
> "John W. Krahn" <someone@example.com> wrote in message news:<7PThd.85034$9b.53687@edtnps84>...
> 
>>Prince Kumar wrote:
>>
>>>I have a file with the following contents.
>>>
>>>drop table tabl1;
>>>
>>>create table tabl1 (
>>>col1
>>>col2
>>>col3);
>>>
>>>drop table tabl2;
>>>
>>>create table tabl2 (
>>>col1
>>>col2);
>>>
>>>..
>>>
>>>I want to replace "create table * );" with 
>>>"create table * ) IN TBSP1;" 
>>>
>>>I tried the following, but I am not getting the desired result.
>>>
>>>perl -p -e 'undef $/; s/^CREATE TABLE (.*?)\);$/CREATE TABLE $1 \) IN
>>>TBSP/s' my_input_file.
>>
>>perl -073pe's/^(\s*create\s+table\s+(\S+)\s+\((?s:.+?)\));/$1 IN \U$2;/i' 
>>my_input_file
 >
 > The given solution works perfect. What does -073 option do?

-073 uses the character ';' as the input record separator


 > Would you also, please explain "((?s:.+?)\))". I tried the perlre, but
 > couldn't understand completely.

That says match a literal '(' character followed by one or more of any 
character including the newline character followed by a literal ')' character. 
  Normally .+? will not match a newline so you need the /s option to allow it 
to match any character.  You could also write it like this:

perl -073pe's/^(\s*create\s+table\s+(\S+)\s+\(.+?\));/$1 IN \U$2;/si' 
my_input_file



John
-- 
use Perl;
program
fulfillment


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

Date: Fri, 12 Nov 2004 19:53:51 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: Script to pass info to GET string
Message-Id: <slrncpa56f.jba.dha@panix2.panix.com>

On 2004-11-12, Shabam <blislecp@hotmail.com> wrote:
>> Oh, a stealth CGI question.
>> Good by then.
>
> What are you talking about?  It's a simple web page cgi.
[snip]
> I'm guessing you think I'm trying to do something bad.  Don't assume,
> without any basis.

I think the only bad thing he thinks you may be doing is asking a
question about CGI in a Perl newsgroup.  Contrary to unfortunately
popular belief, CGI and Perl are not the same thing.  CGI is an
interface, programs for which can be written in various languages
(including) Perl. If your question would be no different if you were
programming in, for instance, C, you probably want to look at a group
that has cgi in its name instead.

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
Nice DNS error you have there.
     - subbes


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

Date: Fri, 12 Nov 2004 15:34:32 -0500
From: wana <ioneabu@yahoo.com>
Subject: Re: simple perl script for automatic form submission.
Message-Id: <10pa48c75raape7@news.supernews.com>

wana wrote:

> sam wrote:
> 
>> Hi,
>> 
>> I m not a perl expert.
>> I would like to write a simple perl script to automatically login my
>> email account that hosted by a commerical webmail server.
>> 
>> Is there any sample script I can follow?
>> 
>> Thanks
>> Sam
> 
> try LWP::UserAgent from CPAN (actually it already came with my Linux
> installation).
> 
> I just started playing with it and was able to get into a site I created
> but I then tried submitting data to some commercial sites and my script
> was rejected with the same form data I was able to submit legitimately
> through
> their webpage.  I am not sure how to 'trick' the site into not knowing if
> it is a web browser or a Perl script trying to submit form data.  I can
> get as far as looking at the html source, finding the form, identifying
> POST or GET, and finding the field names.
> 
> Since I was able to log into my own homemade site, I know it works and is
> not a Perl issue.  'Perl Cookbook' has a brief section on LWP and there is
> probably more in Lincoln Stein's book on Perl networking.
> 
> wana

I just figured out how to do a Google search from a Perl script:

#!/usr/bin/perl
use LWP::UserAgent;
$ua = LWP::UserAgent->new();
$q = $ARGV[0];
$q =~ s/\s/+/g;
$h =
"http://www.google.com/search?hl=en&ie=ISO-8859-1&q=$q&btnG=Google+Search";
$ua->agent("Mozilla/5.0 (compatible; Konqueror/3.1; Linux 2.4.20)");
$resp = $ua->get($h);
$content = $resp->content;
print "$content\n";

Like usual, maybe not the best way, but it does work.  This is really cool!

Couldn't anyone make a search engine 'powered by Google' using something
like this?  I thought it would be neat to include some dynamic Google
search and/or news content on my personal website, but I don't know if it's
legal.  But, then again, don't they reprint other people's material in
their searches?  Sorry, I'm getting off topic, but the implications for a
newbie like me are huge.

wana


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

Date: Fri, 12 Nov 2004 14:11:26 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: simple perl script for automatic form submission.
Message-Id: <121120041411268912%jgibson@mail.arc.nasa.gov>

In article <10pa48c75raape7@news.supernews.com>, wana
<ioneabu@yahoo.com> wrote:


> 
> I just figured out how to do a Google search from a Perl script:
> 
> #!/usr/bin/perl
> use LWP::UserAgent;
> $ua = LWP::UserAgent->new();
> $q = $ARGV[0];
> $q =~ s/\s/+/g;
> $h =
> "http://www.google.com/search?hl=en&ie=ISO-8859-1&q=$q&btnG=Google+Search";
> $ua->agent("Mozilla/5.0 (compatible; Konqueror/3.1; Linux 2.4.20)");
> $resp = $ua->get($h);
> $content = $resp->content;
> print "$content\n";
> 
> Like usual, maybe not the best way, but it does work.  This is really cool!
> 
> Couldn't anyone make a search engine 'powered by Google' using something
> like this?  I thought it would be neat to include some dynamic Google
> search and/or news content on my personal website, but I don't know if it's
> legal.  But, then again, don't they reprint other people's material in
> their searches?  Sorry, I'm getting off topic, but the implications for a
> newbie like me are huge.

Yes, it is legal to add a link to Google on your website, and you can
use this feature to search your own website. However, writing a Perl
program to fetch results is not legal without prior written permission:

<http://www.google.com/services/terms_free.html>


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

Date: 12 Nov 2004 14:58:31 -0800
From: mohammad.munir@gmail.com (Mostafa)
Subject: syntax problem
Message-Id: <c3c09310.0411121458.70f5ab5@posting.google.com>

my($iwperl) = ($^O ne "MSWin32") ? "" : "$iwhome/iw-perl/bin/iwperl ";

here what does thia $^O means ?

and then how "?" is related to this statement?


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

Date: Fri, 12 Nov 2004 19:47:55 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Two operations with one last if?
Message-Id: <Xns959F968A2C542dkwwashere@216.168.3.30>

Uri Guttman <uri@stemsystems.com> wrote:

> i now follow the rule (from peter scott) to use &&/|| in logical
> expressions and and/or for logical flow control (as in open or
> die). it makes more sense and it usually matches the precedence
> very well. 

Do you have a reference for that? I generally use 'and' and 'or' and 
enforce my desired precedence with parens, but I'm willing to be 
persuaded otherwise.


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

Date: Fri, 12 Nov 2004 15:33:41 -0500
From: Uri Guttman <uguttman@athenahealth.com>
Subject: Re: Two operations with one last if?
Message-Id: <m3ekiyhknu.fsf@lap.athenahealth.com>

>>>>> "DKW" == David K Wall <dwall@fastmail.fm> writes:

  DKW> Uri Guttman <uri@stemsystems.com> wrote:
  >> i now follow the rule (from peter scott) to use &&/|| in logical
  >> expressions and and/or for logical flow control (as in open or
  >> die). it makes more sense and it usually matches the precedence
  >> very well. 

  DKW> Do you have a reference for that? I generally use 'and' and 'or' and 
  DKW> enforce my desired precedence with parens, but I'm willing to be 
  DKW> persuaded otherwise.

you do know that &&/|| are the exact same operations as and/or but with
tighter binding? all of them short circuit too.

using parens to control is just added noise IMO. but that depends on the
location of the parens too.

i still tend to use parens with open:

	open( BLAH ... ) || die 'slowly' ;

the () are needed there. that could also be written (horribly) as:

	( open BLAH ... ) || die 'slowly' ;

most perl hackers seem to be dropping the () and using or. this fits the
rule as this is flow control.

	open BLAH ... or die 'faster' ;

but when you get into expressions, you usually want the tighter
binding. this works as expected:

	my $foo = $bar || $default ;

but this doesn't:

	my $foo = $bar or $default ;

adding parens fixes it but at a cost of noise:

	my $foo = ( $bar or $default ) ;

&&/|| work well in expressions since their binding is higher than
assignment. and/or work well in flow control since their binding is
lower than assignment

	$foo = $bar or print "[$bar] isn't true\n" ;

that does what you think it would do. this doesn't:

	$foo = $bar || print "[$bar] isn't true\n" ;

that will print but also assign 1 (the return value of print) to $foo
when $bar is false .

so choose your boolean ops wisely. you may save someone's life! :)

uri




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

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


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