[29083] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 327 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 12 06:09:50 2007

Date: Thu, 12 Apr 2007 03:09:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 12 Apr 2007     Volume: 11 Number: 327

Today's topics:
    Re: Absolute Path errors <nikos1337@gmail.com>
    Re: Absolute Path errors <bik.mido@tiscalinet.it>
        capture voice and send it <jdxyw2004@gmail.com>
    Re: capture voice and send it <spamtrap@dot-app.org>
    Re: Continuous communication between user, CGI script a <sbryce@scottbryce.com>
    Re: My script to download YouTube videos (critique want <ignoramus13850@NOSPAM.13850.invalid>
    Re: My script to download YouTube videos (critique want <tadmc@augustmail.com>
    Re: My script to download YouTube videos (critique want <bugbear@trim_papermule.co.uk_trim>
    Re: My script to download YouTube videos (critique want <bugbear@trim_papermule.co.uk_trim>
    Re: My script to download YouTube videos (critique want <bik.mido@tiscalinet.it>
    Re: My script to download YouTube videos (critique want <bik.mido@tiscalinet.it>
    Re: My script to download YouTube videos (critique want <purlgurl@purlgurl.net>
        new CPAN modules on Thu Apr 12 2007 (Randal Schwartz)
        Search Replace using Hash -p0777 dscastroii@earthlink.net
    Re: Search Replace using Hash -p0777 <tadmc@augustmail.com>
    Re: Search Replace using Hash -p0777 <tadmc@augustmail.com>
    Re: Search Replace using Hash -p0777 <purlgurl@purlgurl.net>
    Re: Search Replace using Hash -p0777 <uri@stemsystems.com>
    Re: Search Replace using Hash -p0777 <purlgurl@purlgurl.net>
    Re: Search Replace using Hash -p0777 <uri@stemsystems.com>
    Re: Top Turds of comp.lang.perl.misc (2007) <1usa@llenroc.ude.invalid>
    Re: Top Turds of comp.lang.perl.misc (2007) krakle@visto.com
    Re: Top Turds of comp.lang.perl.misc (2007) usenet@DavidFilmer.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 12 Apr 2007 01:10:11 -0700
From: "skieros" <nikos1337@gmail.com>
Subject: Re: Absolute Path errors
Message-Id: <1176365411.108153.87530@n76g2000hsh.googlegroups.com>


=CF/=C7 Michele Dondi =DD=E3=F1=E1=F8=E5:
> On 10 Apr 2007 14:27:29 -0700, "?????" <hackeras@gmail.com> wrote:
>
> >> >i only deleted the idnex.html file pointing to index.pl, that all and
> >> >i set DirectoryIndex index.html cgi-bin/index.pl
> >>
> >> What effect does the latter operation create?
> >
> >When a user asks for a webserver directory apache sees iftf there is
> >an index.html file there first, if its not it serves cgi-bin/index.pl
> >if it cant find it then it gives a dirr index.
>
> Well, and when cgi-bin/index.pl is executed, what do you think that
> its cwd will be?

it will be cgi-bin

when index.pl is executed and it passes form data to show.pl print
$ENV{HTTP_REFERRER} which i use in show.pl will say http://localhost
instead of http://index.pl, and i still dotn get that!

index.pl send form data to show.pl so the referes should be index.pl
not document root.

why ti beaves like that? before that i had the index.html redirection
it uses to work ok.



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

Date: Thu, 12 Apr 2007 11:56:32 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Absolute Path errors
Message-Id: <5nvr13h3ns1j5046a7ietofm8d0kglgi4n@4ax.com>

On 12 Apr 2007 01:10:11 -0700, "skieros" <nikos1337@gmail.com> wrote:

>> Well, and when cgi-bin/index.pl is executed, what do you think that
>> its cwd will be?
>
>it will be cgi-bin

Ok, now the answer is staring in front of you: if you open() a file
with a relative path, that will be relative to cgi-bin, NOT its parent
directory.

>when index.pl is executed and it passes form data to show.pl print
>$ENV{HTTP_REFERRER} which i use in show.pl will say http://localhost
>instead of http://index.pl, and i still dotn get that!

You're still confusing two things that stay on opposite sides of a
wall, that have traits resembling each other, but which are in fact
completely different things. $ENV{HTTP_REFERRER} is a networking,
http-related, thing and a priori it has nothing to do with your local
filesystem.

In particular the URL you expect for it does NOT make any sense, for
http://index.pl is not a reasonable URL in any way.

>index.pl send form data to show.pl so the referes should be index.pl
>not document root.
>
>why ti beaves like that? before that i had the index.html redirection
>it uses to work ok.

I'll try to explain again in my own words, which may be technically
inexact for as I said I'm not an expert in these matters: the
webserver has some rules to map some URLS it gets requested into files
to serve or programs to execute, which will spit out some valid
content to serve. The CGI protocol establishes the communication
between the webserver itself and the called program, but the latter is
not aware in any way of the tricks the former performs. Well, to be
fair, as someone explained, actually the webserbver passes along info
that *can be used* to understand them, but you have to do so yourself:
it's NOT an authomatic thing. (And personally I fail to see why/how it
could.)

I know it is frustrating not to understand the real reason behind
something that puzzles you, but if you still don't get it, I recommend
not to worry and for the time being to just accept it along the lines
of "because it's like that, period."


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 11 Apr 2007 19:22:00 -0700
From: "dolphin" <jdxyw2004@gmail.com>
Subject: capture voice and send it
Message-Id: <1176344520.482976.59120@n76g2000hsh.googlegroups.com>

Hi! I want to capture voice from microphone,and send it to another
host just like a phone.what modul can capture sound and send it?



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

Date: Thu, 12 Apr 2007 03:15:17 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: capture voice and send it
Message-Id: <m27isim5bu.fsf@local.wv-www.com>

"dolphin" <jdxyw2004@gmail.com> writes:

> Hi! I want to capture voice from microphone,and send it to another
> host just like a phone.what modul can capture sound and send it?

Sound modules are highly platform-specific - Win32::Sound, Mac::Sound,
Gnome::Sound, SDL::Sound, Audio::OSS, Audio::ESD, etc.

Search for "sound" at <http://search.cpan.org> and see what looks like
a good match for your system.

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Wed, 11 Apr 2007 20:31:05 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Continuous communication between user, CGI script and server
Message-Id: <65SdnQiVEJBKBIDbnZ2dnUVZ_sDinZ2d@comcast.com>

Sherm Pendley wrote:

> Have a look at AJAX.

Also take a look at the CGI::Ajax module. It will do a lot of the client 
side scripting for you.


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

Date: Wed, 11 Apr 2007 20:33:33 -0500
From: Ignoramus13850 <ignoramus13850@NOSPAM.13850.invalid>
Subject: Re: My script to download YouTube videos (critique wanted)
Message-Id: <1oidnfoCFMbwEYDbnZ2dnUVZ_sTinZ2d@giganews.com>

On Wed, 11 Apr 2007 20:56:38 -0500, Tad McClellan <tadmc@augustmail.com> wrote:
> Ignoramus13850 <ignoramus13850@NOSPAM.13850.invalid> wrote:
>
>
>>   for( my $i = 0; $i < 4; $i++ ) {
>
>
>     foreach my $i ( 0 .. 3 ) {
>
>
>>   return undef;
>
>
>    return;  # your code will do the "wrong thing" in list context

I was under (probably wrong) impression that return returns last
computed value.

>
>>       $title = "$1";
>
>         $title = $1;
>
>     perldoc -q vars
>
>        What’s wrong with always quoting "$vars"?

You are right, it happened simply because I had more stuff in that
quoted string than just $1 (.$id.avi), but then I moved it elsewhere.

>
>>       $title =~ s/(\/|\\| |\+|\`|\'|\;|\!|\(|\)|\-)/_/g;
>
> No point in capturing if you are not going to use the captured value.
>
> Most of those backslashes are not needed.
>
> A character class eliminates the vertical bar noise.
>
> With alternate delimiters you don't need to backslash the slash either.
>
>    $title =~ s#[/\\ +`';!()-]#_#g;

I like that. 

> But a year ago I pointed out that a regex was not the right tool
> for the job, and it isn't the right tool for this job either:
>
>    $title =~ tr#/\\ +`';!()-#_#;
>
>>       $title =~ s/_+/_/g;
>
>    $title =~ tr/_/_/s;

OK... thanks... Though I am kind of set in my ways, I will try to keep
with the new approach that you suggested (character classes and tr).

i


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

Date: Wed, 11 Apr 2007 22:28:30 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: My script to download YouTube videos (critique wanted)
Message-Id: <slrnf1r9qu.kmb.tadmc@tadmc30.august.net>

Ignoramus13850 <ignoramus13850@NOSPAM.13850.invalid> wrote:
> On Wed, 11 Apr 2007 20:56:38 -0500, Tad McClellan <tadmc@augustmail.com> wrote:


>>>   return undef;
>>
>>
>>    return;  # your code will do the "wrong thing" in list context
>
> I was under (probably wrong) impression that return returns last
> computed value.


A radical approach that I find useful is to read the documentation
for features that I use.

   perldoc -f return

   ...
   If no EXPR
   is given, returns an empty list in list context, the undefined value in
   scalar context, and (of course) nothing at all in a void context.


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


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

Date: Thu, 12 Apr 2007 09:24:36 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: My script to download YouTube videos (critique wanted)
Message-Id: <461decc5$0$8727$ed2619ec@ptn-nntp-reader02.plus.net>

Michele Dondi wrote:
> On Wed, 11 Apr 2007 14:28:49 -0500, Ignoramus13850
> <ignoramus13850@NOSPAM.13850.invalid> wrote:
> 
>> I wrote a test script to test Purl Gurl's assertion. 
> 
> I wouldn't do it. No way. YMMV...
> 
>> The results are:
>>
>> ### ::~/tmp/perl==>./my.pl
>> ### My took 38 seconds.
>> ### Global took 35 seconds.
> 
> How did you test? On the program you posted before?!? If so, then, are
> you aware that it makes requests through the internet? How do you
> expect that to be reliable?

Actually, it effectively makes the point that the
minor speed loss of "my" (assuming Gurl is right...)
is irrelevant in this context.

As a general piece of editing convenience,
I normally use "my" variable in global scripts,
both to keep "use strict" quiet, and
to facilitate cut 'n' pasting code into subs
if I decide to.

   BugBear


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

Date: Thu, 12 Apr 2007 09:25:29 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: My script to download YouTube videos (critique wanted)
Message-Id: <461decf9$0$8727$ed2619ec@ptn-nntp-reader02.plus.net>

Purl Gurl wrote:
> Incorrect use of declaring a private lexical variable on a global
> basis does reduce script efficiency and is clearly a signature of
> a Perl programmer who is less than acceptably talented.

You're confusing "talent" and "knowledge".

   BugBear


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

Date: Thu, 12 Apr 2007 12:01:25 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: My script to download YouTube videos (critique wanted)
Message-Id: <3p0s13lurilkkhhe439mb74hpieu7pchjs@4ax.com>

On Wed, 11 Apr 2007 13:07:41 -0500, Ignoramus13850
<ignoramus13850@NOSPAM.13850.invalid> wrote:

>      print STDERR "Failed to get url '$url' ($i).\n";

In addition to what others wrote thus far, 

  print STDERR

is generally spelt

  warn


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Thu, 12 Apr 2007 12:06:25 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: My script to download YouTube videos (critique wanted)
Message-Id: <a21s13pfpto7chtkjndnk586sai2iqirpt@4ax.com>

On Wed, 11 Apr 2007 20:56:38 -0500, Tad McClellan
<tadmc@augustmail.com> wrote:

>>   return undef;
>
>
>   return;  # your code will do the "wrong thing" in list context

I would also switch the logic from

  sub get_webpage {
      my $url = shift;
      my $req = HTTP::Request->new(GET => $url);
    
      for( 1..4 ) {
          my $result = get_request $req;
          if( !$result ) {
              warn "Failed to get '$url' ($_).\n";
              next;
          }
          return $result;
      }
      return;
  }

to

  sub get_webpage {
      my $url = shift;
      my $req = HTTP::Request->new(GET => $url);
    
      for( 1..4 ) {
          my $result = get_request $req;
          return $result if $result;
          warn "Failed to get '$url' ($_).\n";
      }
      return;
  }


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Thu, 12 Apr 2007 03:08:04 -0700
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: My script to download YouTube videos (critique wanted)
Message-Id: <NuidnSxzAaWamIPbnZ2dnUVZ_tOmnZ2d@giganews.com>

bugbear wrote:

> Purl Gurl wrote:

>> Incorrect use of declaring a private lexical variable on a global
>> basis does reduce script efficiency and is clearly a signature of
>> a Perl programmer who is less than acceptably talented.

> You're confusing "talent" and "knowledge".

Your adamantly advising readers usage of clearly incorrect
and harmful syntax is acceptable indicates to me you are a
less than talented and a less than knowledgeable programmer.

I am most humored by you boys jumping up and down while screaming,

"Bad Syntax Is Good Syntax!"


Purl Gurl


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

Date: Thu, 12 Apr 2007 04:42:12 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Thu Apr 12 2007
Message-Id: <JGDBqC.xFM@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

Alien-Selenium-0.05
http://search.cpan.org/~domq/Alien-Selenium-0.05/
installing and finding the Selenium Web test framework
----
Angerwhale-0.04
http://search.cpan.org/~jrockway/Angerwhale-0.04/
filesystem-based blog with integrated cryptography
----
App-REPL-0.012
http://search.cpan.org/~ayrnieu/App-REPL-0.012/
A container for functions for the iperl program
----
Archive-Extract-0.18
http://search.cpan.org/~kane/Archive-Extract-0.18/
A generic archive extracting mechanism
----
Business-OnlinePayment-PaymentsGateway-0.02
http://search.cpan.org/~ivan/Business-OnlinePayment-PaymentsGateway-0.02/
PaymentsGateway.Net backend for Business::OnlinePayment
----
Business-OnlinePayment-Skipjack-0.02
http://search.cpan.org/~ivan/Business-OnlinePayment-Skipjack-0.02/
Skipjack backend module for Business::OnlinePayment
----
CGI-Apache2-Wrapper-0.21
http://search.cpan.org/~rkobes/CGI-Apache2-Wrapper-0.21/
CGI.pm-compatible methods via mod_perl
----
Carp-Clan-5.9
http://search.cpan.org/~jjore/Carp-Clan-5.9/
Report errors from perspective of caller of a "clan" of modules
----
Catalyst-Plugin-CRUD-0.15
http://search.cpan.org/~bayside/Catalyst-Plugin-CRUD-0.15/
CRUD (create/read/update/delete) Plugin for Catalyst
----
DateTime-Format-Natural-0.28
http://search.cpan.org/~schubiger/DateTime-Format-Natural-0.28/
Create machine readable date/time with natural parsing logic
----
File-PathInfo-Ext-1.07
http://search.cpan.org/~leocharre/File-PathInfo-Ext-1.07/
metadata files, renaming, some other things on top of PathInfo
----
File-PathInfo-Ext-1.08
http://search.cpan.org/~leocharre/File-PathInfo-Ext-1.08/
metadata files, renaming, some other things on top of PathInfo
----
Finance-Bank-NL-CLIEOP03-0.01
http://search.cpan.org/~zebaz/Finance-Bank-NL-CLIEOP03-0.01/
Generate CLIEOP03 files for Dutch banks.
----
Gungho-0.02_02
http://search.cpan.org/~dmaki/Gungho-0.02_02/
Yet Another High Performance Web Crawler Framework
----
Gungho-0.02_03
http://search.cpan.org/~dmaki/Gungho-0.02_03/
Yet Another High Performance Web Crawler Framework
----
Gungho-0.02_04
http://search.cpan.org/~dmaki/Gungho-0.02_04/
Yet Another High Performance Web Crawler Framework
----
Gungho-0.02_05
http://search.cpan.org/~dmaki/Gungho-0.02_05/
Yet Another High Performance Web Crawler Framework
----
Gungho-0.03
http://search.cpan.org/~dmaki/Gungho-0.03/
Yet Another High Performance Web Crawler Framework
----
Linux-SysInfo-0.01
http://search.cpan.org/~vpit/Linux-SysInfo-0.01/
Perl interface to the sysinfo(2) Linux system call.
----
Math-0.2
http://search.cpan.org/~hooo/Math-0.2/
constants and functions
----
Math-0.3
http://search.cpan.org/~hooo/Math-0.3/
constants and functions
----
Math-Polynom-0.08
http://search.cpan.org/~erwan/Math-Polynom-0.08/
Operations on polynomials
----
Metadata-ByInode-1.11
http://search.cpan.org/~leocharre/Metadata-ByInode-1.11/
Extend metadata in relation to file's inode using a database.
----
Net-DNS-ToolKit-0.31
http://search.cpan.org/~miker/Net-DNS-ToolKit-0.31/
tools for working with DNS packets
----
Net-Pavatar-0.68
http://search.cpan.org/~karjala/Net-Pavatar-0.68/
Pavatar client
----
POE-Component-EasyDBI-1.19
http://search.cpan.org/~xantus/POE-Component-EasyDBI-1.19/
Perl extension for asynchronous non-blocking DBI calls in POE
----
Parallel-Workers-0.0.8
http://search.cpan.org/~evaleto/Parallel-Workers-0.0.8/
run worker tasks in parallel. Worker task is a plugin that you can implement. The availables are Eval for CODE, SSH and XMLRPC.
----
Parallel-Workers-0.0.9
http://search.cpan.org/~evaleto/Parallel-Workers-0.0.9/
run worker tasks in parallel. Worker task is a plugin that you can implement. The availables are Eval for CODE, SSH and XMLRPC.
----
Parse-CPinfo-0.881
http://search.cpan.org/~mmlange/Parse-CPinfo-0.881/
Perl extension to parse output from cpinfo
----
ProgressMonitor-0.06
http://search.cpan.org/~knth/ProgressMonitor-0.06/
a flexible and configurable framework for providing feedback on how a long-running task is proceeding.
----
Router-Statistics-0.99_92
http://search.cpan.org/~shamrock/Router-Statistics-0.99_92/
Router Statistics and Information Collection
----
Win32-Process-List-0.08
http://search.cpan.org/~rpagitsch/Win32-Process-List-0.08/
Perl extension to get all processes and thier PID on a Win32 system


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 11 Apr 2007 18:57:03 -0700
From: dscastroii@earthlink.net
Subject: Search Replace using Hash -p0777
Message-Id: <1176343023.752029.17120@p77g2000hsh.googlegroups.com>

I'm trying to replace ascii codes (or &entities) in a text file with
it's equivalent character using a hash.   The problem I'm running into
is I am not allowed to use a foreach or while loop to do this (yes,
this is a homework assignment).  I must use the -p0777 option with the
#!/usr/bin/perl -p0777 which provides the looping and print function.
I must do this using one line of code only.  I must use the /sg
options in the replace statement to satisfy the instructor's
requirements.

The hash table consists of %entity = ( lt=> '<', gt=> '>', amp=> '&',
'#65'=> 'A', quot=> '"', nbs => chr 160);

I need to loop through a text file that contains these &entities of
variable characters and lengths like so:

&amp; hello
&lt; bye
&#65 sparky

The output should be:
&; hello
<; bye
A; sparky

My code is this:
s/keys %hash/values %hash/sg;

but it does not work.  It does not recognize any the keys or values
and no changes take place.  Does anyone have any suggestions on using
hashes in this kind of situation?  I'm looking for the correct
syntax.  Any suggestions are appreciated.

Debra



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

Date: Wed, 11 Apr 2007 22:35:15 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Search Replace using Hash -p0777
Message-Id: <slrnf1ra7j.kmb.tadmc@tadmc30.august.net>

dscastroii@earthlink.net <dscastroii@earthlink.net> wrote:

> My code is this:
> s/keys %hash/values %hash/sg;
>
> but it does not work.  


Sure it does.


> It does not recognize any the keys or values


That is because there no keys or values or hashes anywhere
in that statement, there are only some percent characters
in a regex and a string, where the percent character is not meta.


> and no changes take place. 


Yes they do:

-------------------------------
#!/usr/bin/perl
use warnings;
use strict;

my %hash;
$_ = 'some keys %hash are here';
s/keys %hash/values %hash/sg;
print "$_\n";
-------------------------------


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


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

Date: Wed, 11 Apr 2007 22:42:40 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Search Replace using Hash -p0777
Message-Id: <slrnf1ralg.kmb.tadmc@tadmc30.august.net>

dscastroii@earthlink.net <dscastroii@earthlink.net> wrote:
> I'm trying to replace ascii codes (or &entities) in a text file with
> it's equivalent character using a hash.   The problem I'm running into
> is I am not allowed to use a foreach or while loop to do this (yes,
> this is a homework assignment).  


That is not a problem at all.


> The hash table consists of %entity = ( lt=> '<', gt=> '>', amp=> '&',
> '#65'=> 'A', quot=> '"', nbs => chr 160);


So the name of the hash is %entity?


> I need to loop through a text file that contains these &entities of
> variable characters and lengths like so:
>
> &amp; hello
> &lt; bye
> &#65 sparky
>
> The output should be:
> &; hello
><; bye
> A; sparky
   ^
   ^
   ^ where did that semicolon come from?


> My code is this:
> s/keys %hash/values %hash/sg;


Where is %hash defined?


> Does anyone have any suggestions on using
> hashes in this kind of situation?  


It looks like the thingies all start with an ampersand character.


> I'm looking for the correct
> syntax.  


You are looking for the correct semantic.


> Any suggestions are appreciated.


Your pattern will need to include an ampersand character
in it somewhere.

You access values from a hash using this syntax:   $entity{amp}

The key in a hash access can be a variable in place of the
constant string in my example.

If you use parenthesis in the correct place in your pattern,
then the matched characters will be placed into a variable.


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


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

Date: Wed, 11 Apr 2007 20:21:14 -0700
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: Search Replace using Hash -p0777
Message-Id: <6audne1JQaswOIDbnZ2dnUVZ_ragnZ2d@giganews.com>

dscastroii wrote:

> I'm trying to replace ascii codes (or &entities) in a text file with
> it's equivalent character using a hash.   The problem I'm running into
> is I am not allowed to use a foreach or while loop to do this (yes,
> this is a homework assignment).  I must use the -p0777 option with the
> #!/usr/bin/perl -p0777 which provides the looping and print function.

> The hash table consists of %entity = ( lt=> '<', gt=> '>', amp=> '&',
> '#65'=> 'A', quot=> '"', nbs => chr 160);

> I need to loop through a text file that contains these &entities of
> variable characters and lengths like so:

> &amp; hello
> &lt; bye
> &#65 sparky

> The output should be:
> &; hello
> <; bye
> A; sparky

This will not be your output based upon the parameters
you present in your article. Additional code is required
to effect this output, beyond what code you present.


> My code is this:
> s/keys %hash/values %hash/sg;

Your hash name is "%entity" not "%hash" as you write.

How is perl core to find those values of your hash?
I do not read your hash being presented to perl core.

Your code will substitute "keys %hash" with "values %hash"
or attempt to do so.

I am not prone to writing homework for others but I will
provide a simple example for you.

Purl Gurl

#!perl

%entity = ( lt=> '<', gt=> '>', amp=> '&', '#65'=> 'A', quot=> '"', nbs => chr 160);

while (<DATA>)
  {
   while (($key, $value) = each %entity)
     { $_ =~ s/$key/$value/; }

   print $_;
  }

__DATA__
&amp; hello
&lt; bye
&#65 sparky


PRINTED RESULTS:

&&; hello
&<; bye
&A sparky


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

Date: Wed, 11 Apr 2007 23:58:52 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Search Replace using Hash -p0777
Message-Id: <x7hcrm1bwj.fsf@mail.sysarch.com>

>>>>> "PG" == Purl Gurl <purlgurl@purlgurl.net> writes:

  >> I'm trying to replace ascii codes (or &entities) in a text file with
  >> it's equivalent character using a hash.   The problem I'm running into
  >> is I am not allowed to use a foreach or while loop to do this (yes,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


  PG> while (<DATA>)
      ^^^^^
  PG>    while (($key, $value) = each %entity)
         ^^^^^

as usual moronzilla doesn't address the actual problem but its
delusional view of it. since when is a while loop (actually 2 of them
and neither is needed) not using a while loop?

  PG>      { $_ =~ s/$key/$value/; }

useless use of $_

  PG>    print $_;

another useless use of $_

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: Wed, 11 Apr 2007 21:14:15 -0700
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: Search Replace using Hash -p0777
Message-Id: <C46dnWk2qfqHL4DbnZ2dnUVZ_jOdnZ2d@giganews.com>

Uri Guttman wrote:

> Purl Gurl wrote:

(snipped childish trolling)

Uri! You are such a comical idiot!

Purl Gurl


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

Date: Thu, 12 Apr 2007 00:24:11 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Search Replace using Hash -p0777
Message-Id: <x7fy76xlsk.fsf@mail.sysarch.com>

>>>>> "PG" == Purl Gurl <purlgurl@purlgurl.net> writes:

  PG> Uri Guttman wrote:
  >> Purl Gurl wrote:

  PG> (snipped childish trolling)

  PG> Uri! You are such a comical idiot!

and you don't know how to read. the OP said NO LOOPS. you used 2
loops. i call that being a moronzilla.

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: Thu, 12 Apr 2007 01:49:06 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Top Turds of comp.lang.perl.misc (2007)
Message-Id: <Xns990FDE066B5CDasu1cornelledu@127.0.0.1>

perl-2007@hotmail.com wrote in news:1176322279.435449.184250
@w1g2000hsg.googlegroups.com:

> Most contributors to comp.lang.perl.misc are helpful and share good
> information. Unfortunately there are a few individuals who are
> frequently rude and abusive. For their bad behavior they are hereby
> named the Top Turds of comp.lang.perl.misc for 2007.

 ...

> 4. A. Sinan Unur ...
> Luckily the a.sinine one has been absent for a while

Actually, no. I am still around, reading and learning as time permits, but 
right now, teaching and research are taking up more of my time than usual.

I am honored that you chose to mention my name along with a few people 
whom I greatly respect (those tend to use their real names when they post 
instead of hiding behind silly monikers).

How's junior high these days?

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



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

Date: 11 Apr 2007 22:00:46 -0700
From: krakle@visto.com
Subject: Re: Top Turds of comp.lang.perl.misc (2007)
Message-Id: <1176354046.861484.36500@n59g2000hsh.googlegroups.com>

On Apr 11, 8:02 pm, Tad McClellan <t...@augustmail.com> wrote:
> perl-2...@hotmail.com <perl-2...@hotmail.com> wrote:
>
> They all post using their real names.
>
> What is your real name?
>
> Or are you more cowardly than they?
>

Or maybe he wishes to remain anonymous since this little thing called
the internet is an anonymous playhouse ;)



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

Date: 12 Apr 2007 02:07:46 -0700
From: usenet@DavidFilmer.com
Subject: Re: Top Turds of comp.lang.perl.misc (2007)
Message-Id: <1176368866.355320.76120@o5g2000hsb.googlegroups.com>

On Apr 11, 6:49 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
> Actually, no. I am still around

That's good to know!  I was a neophyte when you were more active here,
and you taught me a lot.  If you visit OSCON here in Portland, I owe
you a coffee/beer.




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

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 V11 Issue 327
**************************************


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