[25766] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8005 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 22 03:05:40 2005

Date: Fri, 22 Apr 2005 00:05:10 -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           Fri, 22 Apr 2005     Volume: 10 Number: 8005

Today's topics:
        access object <cckk_lin@yahoo.ie>
    Re: access object (Jay Tilton)
    Re: Cgi.pm and CSS [OT] <jwkenne@attglobal.net>
        Emacs modules for Perl programming (Jari Aalto+mail.perl)
    Re: Matching mixed up words (Michael T. Davis)
    Re: Meine geilen Bilder <ariane@freenet.de>
    Re: perl doesn't recogize alias? <matternc@comcast.net>
        searc and replace <freedom@rogers.com>
        search and replace help  <freedom@rogers.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 21 Apr 2005 19:58:17 +0800
From: "Lin Jingxian" <cckk_lin@yahoo.ie>
Subject: access object
Message-Id: <d49gmq$q6b$1@news.yaako.com>

Hi,
I have generate some objects in one subroutine, now I pass the object array
to another subroutine, how can I access the objects.

for example:

use Class::Struct;

struct Field => {
    name=>'$',
    type=>'$',
};

my $field = \Field->new();
$field->name("username");
$field->type("varchar");

my @fields;
push @fields,$field;

show_field(@field);

sub show_field{
    my @fields = @_;

    my $field = shift @fields;
    print $field->name();    ########## here I got : Can't call method
"name" on unblessed reference
    print $field->type();


};

Perl don't think $field as a object, what should I do ?

thanks.




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

Date: Fri, 22 Apr 2005 01:26:12 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: access object
Message-Id: <426850d6.1184473@news.erols.com>

"Lin Jingxian" <cckk_lin@yahoo.ie> wrote:

: I have generate some objects in one subroutine, now I pass the object array
: to another subroutine, how can I access the objects.
: 
: for example:
: 
: use Class::Struct;
: 
: struct Field => {
:     name=>'$',
:     type=>'$',
: };
: 
: my $field = \Field->new();
              ^
Lose that backslash.

: $field->name("username");
: $field->type("varchar");
: 
: my @fields;
: push @fields,$field;
: 
: show_field(@field);
             ^^^^^^
Your array is named @fields, not @field.
"use strict;" would have caught that.

: sub show_field{
:     my @fields = @_;
: 
:     my $field = shift @fields;
:     print $field->name();    ########## here I got : Can't call method
: "name" on unblessed reference

When posting code, be aware of how your news client handles line-wrapping.

:     print $field->type();
: };



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

Date: Thu, 21 Apr 2005 19:57:06 -0400
From: "John W. Kennedy" <jwkenne@attglobal.net>
Subject: Re: Cgi.pm and CSS [OT]
Message-Id: <s5X9e.16268$ZQ1.3332@fe11.lga>

Nikos wrote:
> J. Gleixner wrote:
> 
>> John W. Kennedy wrote:
> 
> 
>>> Whoa! CSS can replace abusive use of <TABLE>, but there are still 
>>> such things in this world as tables.
>>>
>>
>> There are still such things in the world as <font> and <blink> too, it 
>> doesn't mean they should be used. :-)
> 
> 
> By what have they been replaced? In my script i have an extensive use of 
> <table> and <font> and i want o get rid of them :-)

Intelligent use of <div> with CSS can and should replace the use of 
<table> to force layouts. For things that are actual semantic tables, 
such as:

  * |  0  1  2  3  4  5  6  7  8  9            Sing.  Plur.
-----------------------------------    --------------------
  0 |  0  0  0  0  0  0  0  0  0  0      1st | amo    amamus
  1 |  0  1  2  3  4  5  6  7  8  9      2nd | amas   amatis
  2 |  0  2  4  6  8 10 12 14 16 18      3rd | amat   amant
  3 |  0  3  6  9 12 15 18 21 24 27
  4 |  0  4  8 12 16 20 24 28 32 36  or
  5 |  0  5 10 15 20 25 30 35 40 45
  6 |  0  6 12 18 24 30 36 42 48 54
  7 |  0  7 14 21 28 35 42 49 56 63
  8 |  0  8 16 24 32 40 48 56 64 72
  9 |  0  9 18 27 36 45 54 63 72 81

<table> should continue to be used. That's what it's for.

Use of CSS can and should always replace <font>.

<h1><font color="red" size="7">Big headline</h1>

should become

<style type="text/css">
h1.big {color: red; text-size: 400%;}
 ...
</style>
 ...
<h1 class="big">Big headline</h1>



-- 
John W. Kennedy
"Never try to take over the international economy based on a radical 
feminist agenda if you're not sure your leader isn't a transvestite."
   -- David Misch:  "She-Spies", "While You Were Out"


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

Date: 22 Apr 2005 04:32:58 GMT
From: <jari.aalto <AT> poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_1114144353@rtfm.mit.edu>

Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://tiny-tools.sourceforge.net/
Maintainer: Jari Aalto A T poboxes com

Announcement: "What Emacs lisp modules can help with programming Perl"

    Preface

        Emacs is your friend if you have to do anything comcerning software
        development: It offers plug-in modules, written in Emacs lisp
        (elisp) language, that makes all your programmings wishes come
        true. Please introduce yourself to Emacs and your programming era
        will get a new light.

    Where to find Emacs/XEmacs

        o   Unix:
            http://www.gnu.org/software/emacs/emacs.html
            http://www.xemacs.org/

        o   Unix Windows port (for Unix die-hards):
            install http://www.cygwin.com/  which includes native Emacs 21.x.
            and XEmacs port

        o   Pure Native Windows port
            http://www.gnu.org/software/emacs/windows/ntemacs.html
            ftp://ftp.xemacs.org/pub/xemacs/windows/setup.exe

        o   More Emacs resources at
            http://tiny-tools.sourceforge.net/  => Emacs resource page

Emacs Perl Modules

    Cperl -- Perl programming mode

        http://www.cpan.org/modules/by-authors/id/ILYAZ/cperl-mode/
        http://math.berkeley.edu/~ilya/software/emacs/
        by Ilya Zakharevich

        CPerl is major mode for editing perl files. Forget the default
        `perl-mode' that comes with Emacs, this is much better. Comes
        standard in newest Emacs.

    TinyPerl -- Perl related utilities

        http://tiny-tools.sourceforge.net/

        If you ever wonder how to deal with Perl POD pages or how to find
        documentation from all perl manpages, this package is for you.
        Couple of keystrokes and all the documentaion is in your hands.

        o   Instant function help: See documentation of `shift', `pop'...
        o   Show Perl manual pages in *pod* buffer
        o   Grep through all Perl manpages (.pod)
        o   Follow POD references e.g. [perlre] to next pod with RETURN
        o   Coloured pod pages with `font-lock'
        o   Separate `tiperl-pod-view-mode' for jumping topics and pages
            forward and backward in *pod* buffer.

        o   Update `$VERSION' variable with YYYY.MMDD on save.
        o   Load source code into Emacs, like Devel::DProf.pm
        o   Prepare script (version numbering) and Upload it to PAUSE
        o   Generate autoload STUBS (Devel::SelfStubber) for you
            Perl Module (.pm)

    TinyIgrep -- Perl Code browsing and easy grepping

        [TinyIgrep is included in Tiny Tools Kit]

        To grep from all installed Perl modules, define database to
        TinyIgrep. There is example file emacs-rc-tinyigrep.el that shows
        how to set up dattabases for Perl5, Perl4 whatever you have
        installed

        TinyIgrep calls Igrep.el to to do the search, You can adjust
        recursive grep options, set search case sensitivity, add user grep
        options etc.

        You can find latest `igrep.el' module at
        <http://groups.google.com/groups?group=gnu.emacs.sources> The
        maintainer is Jefin Rodgers <kevinr <AT> ihs.com>.

    TinyCompile -- To Browse grep results in Emacs *compile* buffer

        TinyCompile is a minor mode for *compile* buffer from where
        you can collapse unwanted lines or shorten file URLs:

            /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
            /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT

            -->

            cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
            file1:NNN: MATCHED TEXT
            file1:NNN: MATCHED TEXT

End



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

Date: 22 Apr 2005 01:00:20 GMT
From: DAVISM@ecr6.ohio-state.edu (Michael T. Davis)
Subject: Re: Matching mixed up words
Message-Id: <d49ib4$1hb$1@charm.magnus.acs.ohio-state.edu>


In article <3cqi4sF6n2237U1@individual.net>, Fabian Pilkowski
<pilkowsk@informatik.uni-marburg.de> writes:

>* Michael T. Davis schrieb:
>
>> 	I really appreciate all the work you folks have put into answering
>> this for me.  I think I'm close to implementing something, but as you may
>> have guessed, it's time for me to complicate things, again. (;-)
>>
>> 	The whole system I'm developing works like this...  I have some string
>> obtained from an environment variable.  I also have a list of potential
>> pattern matches in a text file.  My code reads the file and attempts to
> match
>> each pattern against the env. string until it hits the end-of-file or a
> match
>> occurs.  Each line from the data file is the argument to a case-insensitive
>> regex match (i.e. "m//i", or -- for the pattern "<pattern>" read from the
>> file -- "m/(<pattern>)/i"), so the code looks something like this:
>>
>> [...]
>> # $string is value obtained from environment
>>               while ( $pattern = <> ) {
>>                   $pattern = '(' . $pattern . ')';
>>                   last if ( $match ) = $string =~ /$pattern/i;
>> [...]         }
>>
>> Since $pattern is basically just what's being read in from the data file,
> I'm
>> looking for a way to handle anagram matching within it.  Here's something
>> along these lines (though it's not correct):
>>
>>           \sg((?i)[a-z]+?)s?\W(?{anagram($+,'host','houl','remlin')})
>>
>> (The Perl code might include "use re 'eval'" [I know...nasty], and will
> include
>> "sub anagram {...}".)  I'm having trouble understanding how I might trigger
> a
>> match for the whole regex iff (if and only if) the result returned by
> anagram()
>> indicates a match.
>
>I think, Abigail has shown such a trick in this thread. Scout about:
>
>    (?(?{grep {$_} values %h})(?!)|)
>
>The inner (?{code}) is what you want to eval, surrounded by a construct
>called
>
>    (?(condition)yes-pattern|no-pattern)
>
>in `perldoc perlre`. Furthermore, »(?!)« never matchs, while the empty
>pattern matchs always.

	OK, so I need to modify my test pattern as follows:

     \sg((?i)[a-z]+?)s?\W(?(?{anagram($+,'host','houl','remlin')}).*$|(?!))

I read this as...

 Match a (plural) anagram of "ghost", "ghoul" or "gremlin" with a leading
 white-space character and a trailing non-word character. If the anagram
 matches, consume the rest of the line; otherwise, let the match fail.

Here's my anagram code:

use re 'eval';

    sub anagram
    {
        my ( $result, $t, $target );

        $result = '';
        $target = shift ( @_ );
        $t = join "", sort { lc ( $a ) cmp lc ( $b ) } split //, $target;
        foreach $word ( @_ )
        {
            my $w;
            next if length ( $word ) != length ( $target );
            $w = join "", sort { lc ( $a ) cmp lc ( $b ) } split //, $word;
            $result = $w eq $t;
            last if $result
        }
        if ( $result )
        {
            return $target
        }
        else
        {
            return $result
        }
    }

Through a diagnosic print statement, I can confirm that my test string of
" ermlgin " would match, but the match test that calls anagram via re-eval
isn't matching:

                      ( $match ) = $string =~ /($pattern)/i

($string = " ermlgin " and $pattern is the pattern, above.)  What am I
missing?

>
>> (If there's a way to avoid "use re 'eval'", that would be
>> helpful, too.)
>
>You're reading the patterns from a file, so you have them in vars. And
>one has to use »use re 'eval'« if you have (?{code}) blocks and variable
>interpolation in one regex. But, have you read `perldoc re` already?
>Especially:
>
>    For the purpose of this pragma, interpolation of precompiled regular
>    expressions (i.e., the result of qr//) is not considered variable
>    interpolation. Thus:
>
>        /foo${pat}bar/
>
>    is allowed if $pat is a precompiled regular expression, even if $pat
>    contains (?{ ... }) assertions.
>
>Perhaps this precompilation could help you.

    Yeah, I'll look into the potential of integrating this, once I can get
the matching to work.

>
>regards,
>fabian

Thanks,
Mike
--
                                         |    Systems Specialist: CBE,MSE
             Michael T. Davis            | Departmental Networking/Computing
 http://www.ecr6.ohio-state.edu/~davism/ |     The Ohio State University
                                         |     197 Watts, (614) 292-6928


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

Date: Fri, 22 Apr 2005 06:42:32 +0200
From: "Ariane" <ariane@freenet.de>
Subject: Re: Meine geilen Bilder
Message-Id: <42687fa2$1$17971$6d4158fb@reader-1.xsnews.nl>

Hi, hier sind meine geilen Bilder!
My nude Pics!!!
http://www.geile-tipps.info/go/ 

--
Posted by News Bulk Poster
Unregistered version


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

Date: Thu, 21 Apr 2005 18:44:50 -0400
From: Chris Mattern <matternc@comcast.net>
Subject: Re: perl doesn't recogize alias?
Message-Id: <xKSdnVoT2fd_sfXfRVn-1A@comcast.com>

Axel wrote:

> Chris Mattern <matternc@comcast.net> wrote:
>>> On bash shell, I did:
>>> alias gcc='grep'
> 
>>> Then I wrote a perl script with only one line:
>>> `gcc -v`;
>  
>> Perl has a rule about how it handles backticks (and similar calling
>> of external programs).  If it has shell metacharacters in it, it
>> passes the string to /bin/sh.  If it doesn't, it passes the string
>> to exec().  Your example gets passed to exec(), so no shell aliases
>> for you!
> 
> Even using shell metacharacters would not help since the alias would not
> be inherited.
> 
> I suppose you could place the alias in a startup file, remembering
> that the behaviour of bash in reading startup files differs according
> to whether it is invoked by the name 'sh' or 'bash'.

And that's on Linux.  On, say, Solaris, where /bin/sh is an honest-to-
Ritchie real Borune shell, you can't even get that, because you've
got no aliases, period.
> 
> Axel

-- 
             Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"


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

Date: Fri, 22 Apr 2005 02:10:42 -0400
From: "freedom" <freedom@rogers.com>
Subject: searc and replace
Message-Id: <5eCdnfVA9ej-CPXfRVn-qg@rogers.com>

I m a newbie in perl and just try to finish an assignment. I generate an
html form with CGI.pm. If the user enter a url in the first textfield, that
url supposed to be loaded wit LWP. In the second text field if the user
enter a tag or a filename it is supposed to search and it should be replaced
whatever user entered in the third field.
The problems:
1.I m getting text document instead of html source code when i enter a url
in the first textfield..
2. I can not do the search and replace in the second and third field

any help please. I will be so thankful

this is my generated form script
#!/usr/bin/perl
use strict;
use CGI qw( :standard );
use CGI::Carp qw(fatalsToBrowser);

print( header() );
print( start_html(-title => 'Online XHTML Change Form' ) );

print <<FORM;
<form action = "start.cgi" method = "post">
<p>Option:
<select name = "option">
<option selected>URL</option>
<option>File</option>
<option>Tag</option>
</select>
<p>URL of page to be changed:
<input name = "url" type = "text" size = "50"></p>
<p>Name of file, tag or url to be changed:
<input name = "text" type = "text" value="$_" size = "50"></p>
<p>Name to be changed:
<input name = "pattern" type = "text" value="$pattern" size = "50"></p>
<input type = "submit" value = "submit">
</form>
FORM

print( end_html() );


this is the html parsing , search and replace. I called it start.cgi

#!/usr/bin/perl

use strict;
use warnings;
use CGI qw( :standard );
use CGI::Carp qw(fatalsToBrowser);
use LWP::UserAgent;
use HTML::TokeParser;

my $url = param( "url" );
my $option = param( "option");
my $agent = new LWP::UserAgent();
my $request = new HTTP::Request( 'GET' => $url );
my $response = $agent->request( $request );
my $document = $response->content();
my $page = new HTML::TokeParser( \$document );

while ( my $token = $page->get_token() ) {
 my $type = shift( @{ $token } );
 my $url = shift( @{ $token } );

 if ($type eq "T" ) {
  print( "$url" );
  }
 }

    $_ = param( "text" );
    $pattern = param( "pattern" );

if( $option == "URL" ) {
 my $string = get($url);
 s/$_/$pattern/;
}

if (!$url ) {
print( start_html() );
print( h4( "Url field should not be blank." ) );
print( h4("Please try again.") );
print( "<a href = \"/assign2.cgi\">Go back</a>" );
print( end_html() );
exit();
}






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

Date: Fri, 22 Apr 2005 01:11:19 -0400
From: "freedom" <freedom@rogers.com>
Subject: search and replace help 
Message-Id: <R9edne2N-4fvGvXfRVn-gA@rogers.com>

I m a newbie in perl and just try to finish an assignment. I generate an 
html form with CGI.pm. If the user enter a url in the first textfield, that 
url supposed to be loaded wit LWP. In the second text field if the user 
enter a tag or a filename it is supposed to search and it should be replaced 
whatever user entered in the third field.
The problems:
1.I m getting text document instead of html source code when i enter a url 
in the first textfield..
2. I can not do the search and replace in the second and third field

any help please. I will be so thankful

this is my generated form script
#!/usr/bin/perl
use strict;
use CGI qw( :standard );
use CGI::Carp qw(fatalsToBrowser);

print( header() );
print( start_html(-title => 'Online XHTML Change Form' ) );

print <<FORM;
<form action = "start.cgi" method = "post">
<p>Option:
<select name = "option">
<option selected>URL</option>
<option>File</option>
<option>Tag</option>
</select>
<p>URL of page to be changed:
<input name = "url" type = "text" size = "50"></p>
<p>Name of file, tag or url to be changed:
<input name = "text" type = "text" value="$_" size = "50"></p>
<p>Name to be changed:
<input name = "pattern" type = "text" value="$pattern" size = "50"></p>
<input type = "submit" value = "submit">
</form>
FORM

print( end_html() );


this is the html parsing , search and replace. I called it start.cgi

#!/usr/bin/perl

use strict;
use warnings;
use CGI qw( :standard );
use CGI::Carp qw(fatalsToBrowser);
use LWP::UserAgent;
use HTML::TokeParser;

my $url = param( "url" );
my $option = param( "option");
my $agent = new LWP::UserAgent();
my $request = new HTTP::Request( 'GET' => $url );
my $response = $agent->request( $request );
my $document = $response->content();
my $page = new HTML::TokeParser( \$document );

while ( my $token = $page->get_token() ) {
 my $type = shift( @{ $token } );
 my $url = shift( @{ $token } );

 if ($type eq "T" ) {
  print( "$url" );
  }
 }

    $_ = param( "text" );
    $pattern = param( "pattern" );

if( $option == "URL" ) {
 my $string = get($url);
 s/$_/$pattern/;
}

if (!$url ) {
print( start_html() );
print( h4( "Url field should not be blank." ) );
print( h4("Please try again.") );
print( "<a href = \"/assign2.cgi\">Go back</a>" );
print( end_html() );
exit();
}





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

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


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