[23339] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5559 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 25 09:05:54 2003

Date: Thu, 25 Sep 2003 06:05:13 -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, 25 Sep 2003     Volume: 10 Number: 5559

Today's topics:
    Re: 1) How to debug CGI.pm cookies 2) Template.pm with  <u_cant_mail_me@medid.nl>
    Re: 1) How to debug CGI.pm cookies 2) Template.pm with  (Mr I)
    Re: basic subroutine question. (fabre)
    Re: basic subroutine question. (Anno Siegel)
        bespoke pdf printing using Perl (jimbo2112)
        Checking if a file exists within @INC <newsonly@pmburtonNOT-THIS.claraORTHIS.co.uk>
    Re: class methods <mpapec@yahoo.com>
    Re: class methods (Anno Siegel)
        Compiling perl with GCC <marcus@automint.co.uk>
    Re: Compiling perl with GCC <thaynes@openlinksw.com>
    Re: Compiling perl with GCC <marcus@automint.co.uk>
        CPAN <madunix@web.de>
    Re: Expert: What is wrong here? (Jay Tilton)
        I am sure this was working so what's wrong now - help n <none@none.com>
    Re: I am sure this was working so what's wrong now - he <peter@semantico.com>
    Re: I am sure this was working so what's wrong now - he <none@none.com>
    Re: I am sure this was working so what's wrong now - he <peter@semantico.com>
    Re: I am sure this was working so what's wrong now - he (Anno Siegel)
    Re: I am sure this was working so what's wrong now - he <none@none.com>
    Re: I am sure this was working so what's wrong now - he <none@none.com>
    Re: Mapping characters in a string (Anno Siegel)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 25 Sep 2003 11:15:20 +0200
From: Frodo Larik <u_cant_mail_me@medid.nl>
Subject: Re: 1) How to debug CGI.pm cookies 2) Template.pm with CGI.pm
Message-Id: <3f72b228$0$58715$e4fe514c@news.xs4all.nl>

Mr I wrote:

> How does one view the content of a cookie when it is submitted by the
> client browser?

I use this:

sub get_Cookie()
{
    my $lookfor = $_[0];
    my $cookie;

    if ( defined($ENV{'HTTP_COOKIE'})  )
    {
       foreach $cookie ( split (/; /,$ENV{'HTTP_COOKIE'}) )
       {
          if ( $cookie =~ /^$lookfor=/ )
          {
             my $value = $cookie;
             $value =~ s/^$lookfor=//;
             return $value;
          }
       }
    }
    return "1";
}


and i get the content by using the name of the cookie, so if cookie is 
called 'bla', my $value = &get_Cookie('bla');

Sincerly,

Frodo Larik




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

Date: 25 Sep 2003 02:29:10 -0700
From: konny@waitrose.com (Mr I)
Subject: Re: 1) How to debug CGI.pm cookies 2) Template.pm with CGI.pm
Message-Id: <6985a862.0309250129.4862afa8@posting.google.com>

Tore Aursand <tore@aursand.no> wrote in message news:<pan.2003.09.25.00.00.32.990480@aursand.no>...
> On Wed, 24 Sep 2003 15:39:22 -0700, Mr I wrote:
> > 1) debugging CGI.pm cookies
> > How does one view the content of a cookie when it is submitted by the
> > client browser?
> 
> Personally, almost everything related to debugging is "done by" by a Log
> module I'm using.  In my code I could write:
> 
>   my $cookie_value = $cgi->cookie( 'auth_my_site' );
>   $Log->debug( 'Found cookie: ' . $cookie_value );
> 
> On one of my virtual desktops (I'm running Gnome) I have a terminal
> windows open where i 'tail' Apache's error log.  Voilá! :-)
> 
Ditto.. just not using log module...
> > Currently I use a combination of print statments and Data::Dumper,
> > surely there must be an inbuilt method.
> 
> No.  Perl is a programming language.  It's not intended to be used for
> debugging HTTP data. :-)
> 
clarify my statement:
surely CGI.pm has an inbuilt method (not directed @perl)

> What's your excact problem, really?  I'm familiar with the 'I want to
> authenticate users by using a cookie'-problem, but I really can't see
> what's so hard about it?
> 
My problem is tracing errors. I just wish to speed up my error
diagnostic times.
The BEST method would be to do diagnostic via command line (which
CGI.pm supports) however I have no idea how to import cookie
information into my code via the command line (in the same mannor you
can with name, value pairs).

> 
> > undef error - Undefined subroutine CGI::failure
> >  at (eval 12) line 9
> 
> Well.  Stop giving us a "subsection of the code" and rather give us what's
> on that particular line (and related code)!

All the important parts are there, in fact if you executed the script
minimal changes (i.e. add use statements, adding #!/path/to/perl,
creating foo.tt with TT syntax inside etc) you will get a similar
error.

> 
> On the other hand;  Is there a 'failure' subroutine in CGI.pm?  Never
> heard of it.
Indeed. as the error states it seems to be the lack of subroutine
"failure" in CGI.pm that is causing the error...
Another clarification:
The subroutine changes depending on the values of $query->param.. 
am slllooowwlly getting an understanding... however would like to call
on knowledge of experinced CGI.pm / Template.pm users..
 
> 
> Haven't used Template.pm, though, so if that's where the problem is, I
> can't help much.
Thanks in any case :)


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

Date: Thu, 25 Sep 2003 13:32:18 +0100
From: pedro.fabre.NO-SPAM@gen.gu.se (fabre)
Subject: Re: basic subroutine question.
Message-Id: <pedro.fabre.NO-SPAM-2509031332180001@192.168.0.5>

In article <bkp3jh$d4d$1@mamenchi.zrz.TU-Berlin.DE>,
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:

> The sub "remove_col" is much more complicated than it has to be.
> I haven't looked too closely, but you are using far too many indices.
> That is rarely necessary in Perl.  I haven't analyzed it beyond that.
> 
> > My intention is:
> > 
> > 1       2       3       4       5
> > 2       10      7       15      14
> > 
> > take out columns 0 and 2
> > 
> > 2       4       5
> > 10      15      14
> > 
> > and after that remove 0 and 1
> > 
> > returning:
> > 
> > 5
> > 14
> > 
> > 
> > I am confuse because the program returns
> 
> [snip confusion]
> 
> This works as you intended:
> 
>     sub remove_col {
>         my ( $lol, $remove) = @_;
>         for my $col ( reverse @$remove ) {
>             print "removing column $col\n";
              splice @$_, $col, 1 for @$lol;
>             
>         }
>     }
> 
> The only non-obvious bit is "reverse" in the for-loop control.  It makes
> sure that the last columns are removed first, so as not to upset the
> index positions of columns not yet removed.  This assumes that columns
> are given in ascending order in the first place.
> 
> Anno

Hi Anno, you have impressed me with the elegancy of your code. Clear and simple.

very clever start to remove from the end.

but still I am lost with the splice part. I think you pass every array on
the second level. But I don't undestand hoy you operate over all the
columns just at once. Brilliant code but confuse for a rookie. Now more
than ever I know I have to turn into perl to do the things easier.

Thanks for you magic!

P


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

Date: 25 Sep 2003 12:52:44 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: basic subroutine question.
Message-Id: <bkuoes$fp4$2@mamenchi.zrz.TU-Berlin.DE>

fabre <pedro.fabre.NO-SPAM@gen.gu.se> wrote in comp.lang.perl.misc:
> In article <bkp3jh$d4d$1@mamenchi.zrz.TU-Berlin.DE>,
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> 
> > The sub "remove_col" is much more complicated than it has to be.
> > I haven't looked too closely, but you are using far too many indices.
> > That is rarely necessary in Perl.  I haven't analyzed it beyond that.
> > 
> > > My intention is:
> > > 
> > > 1       2       3       4       5
> > > 2       10      7       15      14
> > > 
> > > take out columns 0 and 2
> > > 
> > > 2       4       5
> > > 10      15      14
> > > 
> > > and after that remove 0 and 1
> > > 
> > > returning:
> > > 
> > > 5
> > > 14
> > > 
> > > 
> > > I am confuse because the program returns
> > 
> > [snip confusion]
> > 
> > This works as you intended:
> > 
> >     sub remove_col {
> >         my ( $lol, $remove) = @_;
> >         for my $col ( reverse @$remove ) {
> >             print "removing column $col\n";

The "print..." line shouldn't be there, of course.  I forgot to
remove it.

>               splice @$_, $col, 1 for @$lol;
> >             
> >         }
> >     }
> > 
> > The only non-obvious bit is "reverse" in the for-loop control.  It makes
> > sure that the last columns are removed first, so as not to upset the
> > index positions of columns not yet removed.  This assumes that columns
> > are given in ascending order in the first place.
> > 
> > Anno
> 
> Hi Anno, you have impressed me with the elegancy of your code. Clear and simple.
> 
> very clever start to remove from the end.
> 
> but still I am lost with the splice part. I think you pass every array on
> the second level. But I don't undestand hoy you operate over all the
> columns just at once.

That's the inconspicuous-looking "for @$lol" after splice().  Each element
of "@$lol" is a reference to one of the bottom-level arrays, so the
splice is done for all of those lists.

Anno


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

Date: 25 Sep 2003 04:16:36 -0700
From: mjames@bmjgroup.com (jimbo2112)
Subject: bespoke pdf printing using Perl
Message-Id: <41b43f9c.0309250316.4a5157ec@posting.google.com>

Hi All,

First post here!

I am running Perl 5.8 on NT 4.0

I have set up an FTP print server which automates the printing of any
pdf dropped into a watched folder before sending it to a holding area
where, after 3 days, it will be deleted.

I need to make the process more sophistcated by having 3 ftp folders.
These would be to either send it to a mono printer, send to a colour
printer or print only the first page (mono).

The problem I have is that the line command options for Acrobat are
very restricted.

Does anyone have any ideas on what I could plug into the Perl scripts
get what I want? Is there a module that I can use? I am very new to
Perl, so please be gentle with me!

Cheers

Jimbo


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

Date: Thu, 25 Sep 2003 10:38:39 +0100
From: Paul Burton <newsonly@pmburtonNOT-THIS.claraORTHIS.co.uk>
Subject: Checking if a file exists within @INC
Message-Id: <3F72B79F.5090806@pmburtonNOT-THIS.claraORTHIS.co.uk>

I'm using the "do" function to read in a system configuration file 
(which is just another perl script). "do" will search for the file using 
the @INC path list.

The name of the file which is read is supplied by the user, so there is 
the potential that the specified file doesn't exist.

Although I can put a check around the "do" statement to generate an 
error and crash out, I'd really like to do this check at the top of the 
program, where I'm checking all the user inputs are correct.

However, at this point I don't want to execute the "do". What I want is 
a function which will search through the @INC directories and return an 
error if the specified file is not found there, or the name of the first 
directory matched otherwise.

Of course I could write my own to do this. But, I figure that all the 
functions which use @INC (do, use, require etc.) must have to do 
something like this already, so I thought there would be something 
available to me to let me do this.

But, I can't find this. Can someone point me to something suitable, or 
will I have to write my own?

TIA

Paul.



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

Date: Thu, 25 Sep 2003 10:34:20 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: class methods
Message-Id: <3r95nvoe9tq3afrvi4hsvnjj8nc5pth66f@4ax.com>

On Wed, 24 Sep 2003 23:55:24 +0200, Tore Aursand <tore@aursand.no>
wrote:

>> Even in cases when method isn't directly manipulating $MyObject but
>> impacting a whole class?
>
>I'll be the first to admit that I'm not an OO guru; I've never been
>teached "proper OO" (if there's such a thing) by a teacher (never attended
>computer science at school), and I might not be familiar with the OO
>terminology.  I have, however, been programming "OO-style" for several
>years (since the early 90's).  And I've read Damian Conway's excellent
>book about OO programming in Perl. :-)
>
>And:
>There is no such thing as "manipulating a whole class", or - as you
>describe it - impacting a whole class.  You never work with _classes_. 
>You work with objects, which are _instances of classes_.

I'm no OO expert neither but AFAIR, perl books talk about
object/instance methods and class methods. Class methods are afaik
called "static" in c++.



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

Date: 25 Sep 2003 12:38:29 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: class methods
Message-Id: <bkunk5$fp4$1@mamenchi.zrz.TU-Berlin.DE>

Tore Aursand  <tore@aursand.no> wrote in comp.lang.perl.misc:
> On Wed, 24 Sep 2003 18:55:38 +0200, Matija Papec wrote:
> >> Seems like bad behaviour in my eyes, but then again I've never used
> >> anything else than this syntax:
> >>
> >>   my $MyObject = MyClass->new();
> >>   $MyObject->foo();
> 
> > Even in cases when method isn't directly manipulating $MyObject but
> > impacting a whole class?
> 
> I'll be the first to admit that I'm not an OO guru; I've never been
> teached "proper OO" (if there's such a thing) by a teacher (never attended
> computer science at school), and I might not be familiar with the OO
> terminology.  I have, however, been programming "OO-style" for several
> years (since the early 90's).  And I've read Damian Conway's excellent
> book about OO programming in Perl. :-)
> 
> And:
> 
> There is no such thing as "manipulating a whole class", or - as you
> describe it - impacting a whole class.  You never work with _classes_. 
> You work with objects, which are _instances of classes_.

What makes you say that?  Manipulation of the whole class is quite
possible and that's what class method calls are for.  Typical examples
are language switching, making certain errors fatal, defining defaults
and lots more.  Operations like these *should* be written as class
methods, because calling them through a specific object would be
misleading.

A limiting case is the constructor method (new()), which is generally
also a class method, though it does pertain to a specific object.

> Therefore, IMO, one should avoid calling a class' method without going
> through an instance of the class (even if this is possible in Perl).

Class methods are generally much rarer than object methods, but they
have their place.

> If you're "manipulating a class directly", there is no need for objects
> (or classes) in the first place.

What are you thinking of when you say "manipulating a class directly"?
The examples I gave above certainly make sense in an object oriented
setting.

>                                   You would be dealing with "ordinary Perl
> modules", which _will_ be troublesome in the long run.
> 
> Cutting from an other post from you:
> 
> > So basicaly it would be safest to call Foo()
> > $self->Foo(); within the package [...]
> 
> Yes.  If the method 'Foo()' is a member of the same _class_.  Please be
> specific when you're talking about packages/modules and/or classes.  There
> is a difference.
> 
> > [...] and SomeClass->Foo(); from other packages?
> 
> No.  You _should not_ call the class' method directly.  You should rather,
> as I've already pointed out, call the method on an instance (ie. an
> object) of the class.

A method should normally be either a class method or an object method,
and should be called accordingly.  There is nothing wrong with calling
a class method through its package name, though this wouldn't depend on
from where it is called.

Calling a method as an ordinary sub is something else and should not
be done, because that would break inheritance.

Anno


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

Date: Thu, 25 Sep 2003 12:47:20 +0100
From: Marcus <marcus@automint.co.uk>
Subject: Compiling perl with GCC
Message-Id: <MPG.19dce60cd0411dc7989688@192.168.1.50>

I was unable to compile some perl modules, because after running #perl 
Makefile.PL running #make was trying to call up /usr/bin/cc rather than 
gcc. 

After looking at newsqroups I got the impression that I needed to either 
purchase the commercial sun compiler that uses the cc command or 
recompile perl from source using gcc (my current perl was already 
installed as part of the linux install). 

So being unable to justify the expense of the first option, I went for 
the second. 

#./Configure went through seemingly fine. When I ran #make or #make test 
though I ran into errors. 

------------------------------------------------------------------------
#make test
`sh  cflags "optimize='-03'" toke.o`  toke.c
          CCCMD = gcc -DPERL_CORE -c -fno-strict-aliasing -
D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -03 -wall
gcc: Internal Error: Terminated (program cc1)
Please submit a full bug report. 
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
make: *** [toke.o] Error 1
#
------------------------------------------------------------------------

Any ideas? It seems vague and doesn't give me much of a clue. 

I haven't submitted a full bug report. I haven't got all the information 
asked for. For instance my GCC was installed from an RPM (I didn't have 
a compiler before that), so I don't know all the configure options used. 

I am running GCC 3.3.1 on Peanut Linux 9.5 with kernel 2.4.20. Trying to 
compile perl 5.8.0 from source having gone through configure using 
default options apart from one minor change to a path setting. 

Regards,

Marcus Thornton.




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

Date: Thu, 25 Sep 2003 11:49:47 +0100
From: Tim Haynes <thaynes@openlinksw.com>
Subject: Re: Compiling perl with GCC
Message-Id: <87smmlf8hg.fsf@purple.uknet.private>

Marcus <marcus@automint.co.uk> writes:

[snip]
> #make test
> `sh  cflags "optimize='-03'" toke.o`  toke.c
>           CCCMD = gcc -DPERL_CORE -c -fno-strict-aliasing -
> D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -03 -wall
> gcc: Internal Error: Terminated (program cc1)
> Please submit a full bug report. 
[snip]
>
> Any ideas? It seems vague and doesn't give me much of a clue. 

First of all, try it without the -O3 in there. -O2 is probably all you
need, or take it out altogether.

~Tim
-- 
Product Development Consultant
OpenLink Software
Tel: +44 (0) 20 8681 7701
Web: <http://www.openlinksw.com>
Universal Data Access & Data Integration Technology Providers


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

Date: Thu, 25 Sep 2003 13:23:47 +0100
From: Marcus <marcus@automint.co.uk>
Subject: Re: Compiling perl with GCC
Message-Id: <MPG.19dcee9096ec8875989689@192.168.1.50>

In article <87smmlf8hg.fsf@purple.uknet.private>, thaynes@openlinksw.com 
says...
> Marcus <marcus@automint.co.uk> writes:
> 
> [snip]
> > #make test
> > `sh  cflags "optimize='-03'" toke.o`  toke.c
> >           CCCMD = gcc -DPERL_CORE -c -fno-strict-aliasing -
> > D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -03 -wall
> > gcc: Internal Error: Terminated (program cc1)
> > Please submit a full bug report. 
> [snip]
> >
> > Any ideas? It seems vague and doesn't give me much of a clue. 
> 
> First of all, try it without the -O3 in there. -O2 is probably all you
> need, or take it out altogether.
> 
> ~Tim
> 


OK tried changing the -03 in the makefile to -02 and it looked better 
and got further, checking file dependencies, but then produced the same 
line as before (except obviously with -02 instead of -03) before 
producing the same error. 

Thank you, but any more ideas?

Regards,

Marcus Thornton.


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

Date: Thu, 25 Sep 2003 15:42:08 +0200
From: "MaDuNiX" <madunix@web.de>
Subject: CPAN
Message-Id: <bkunrh$5sdf5$1@ID-172702.news.uni-berlin.de>

I am trying to install Bundle CPAN on my AIX 5.1

perl -MCPAN -e 'install Bundle::CPAN'
 ....................
cp ReadKey.pm blib/lib/Term/ReadKey.pm
AutoSplitting blib/lib/Term/ReadKey.pm (blib/lib/auto/Term/ReadKey)
        /usr/bin/perl "-I/usr/opt/perl5/lib/5.6.0/aix"
"-I/usr/opt/perl5/lib/5.6.0" -e 'use ExtUtils::Mksymlists;
Mksymlists("NAME" => "Term::ReadKey", "DL_FUNCS" => {  }, "FUNCLIST" => [],
"DL_VARS" => []);'
        /usr/bin/perl -I/usr/opt/perl5/lib/5.6.0 genchars.pl

Writing termio/termios section of cchars.h... Done.
Checking for sgtty...
        Sgtty NOT found.
Writing sgtty section of cchars.h... Done.



     /usr/bin/perl -I/usr/opt/perl5/lib/5.6.0/aix -I/usr/opt/perl5/lib/5.6.0
/usr/opt/perl5/lib/5.6.0/ExtUtils/xsubpp -noprototypes -typemap
/usr/opt/perl5/lib/5.6.0/ExtUtils/typemap ReadKey.xs > ReadKey.xsc && mv
ReadKey.xsc ReadKey.c








cc -c  -D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE -qmaxmem=16384 -q32 -D
_LARGE_FILES -qlonglong -O      -DVERSION=\"2.21\"  -DXS_VERSION=\"2.21\"  -
I/usr/opt/perl5/lib/5.6.0/aix/CORE  ReadKey.c
/bin/sh: cc:  not found.
make: 1254-004 The error code from the last command is 127.


Stop.
  /usr/bin/make  -- NOT OK
Running make test
  Can't test without successful make
Running make install
  make had returned bad status, install seems impossible
Term::ReadLine::Perl is up to date.
CPAN is up to date.
Bundle summary: The following items in bundle Bundle::CPAN had installation
problems:
  Digest::MD5 Compress::Zlib Bundle::libnet Term::ReadKey and the following
  items had problems during recursive bundle calls: Data::Dumper


# perl -v

This is perl, v5.6.0 built for aix

Copyright 1987-2000, Larry Wall

Perl may be copied only under the terms of either the Artistic License or
the
GNU General Public License, which may be found in the Perl 5.0 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'.  If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.



Any help?





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

Date: Thu, 25 Sep 2003 04:48:05 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Expert: What is wrong here?
Message-Id: <3f727251.128727622@news.erols.com>

deals@slip-12-64-108-121.mis.prserv.net (Great Deals) wrote:

: local $matchkey = $_[0];
: i changed one thing and it works, but i don't know why? why local
: works, my does not?

Because now $matchkey is a global variable instead of a lexical.
&callback is no longer a broken closure; it's an ordinary sub.

: i don't want to change \&callback because it is the STANDRED example
: in LinkExtor help file. So i think there is nothing wrong there.

Long live the Cargo Cult.



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

Date: Thu, 25 Sep 2003 10:43:42 GMT
From: "John" <none@none.com>
Subject: I am sure this was working so what's wrong now - help needed
Message-Id: <yFzcb.122457$bo1.112123@news-server.bigpond.net.au>

Hi,

I'm using this from http://www.perldoc.com/perl5.004_05/pod/perlfaq5.html to
do a string substitution in a HTML file:

    $old = $file;
    $new = "$file.tmp.$$";
    $bak = "$file.bak";

    open(OLD, "< $old")  or die "can't open $old: $!";
    open(NEW, "> $new")  or die "can't open $new: $!";

    # Correct typos, preserving case
    while (<OLD>) {
         ...
###########################The below concerns me
        if ($_ =~ "A HREF=") {
            my $link = $_;
            $link =~ s/href="([^"]+)"/my
$x=$1;$x=~s#One#Two#g;'href="'.$x.'"'/ei;
        }
        (print NEW $_);
    }
###########################The above concerns me

    close(OLD)   or die "can't close $old: $!";
    close(NEW)    or die "can't close $new: $!";

    rename($old, $bak)  or die "can't rename $old to $bak: $!";
    rename($new, $old)  or die "can't rename $new to $old: $!";


I'm expecting the contents of the file to change from:
<A HREF="One/One/one/One.html"> One link
to:
<A HREF="Two/Two/one/Two.html"> One link
but it still reads:
<A HREF="One/One/one/One.html"> One link

Any help will be greatly appreciated...











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

Date: Thu, 25 Sep 2003 11:53:35 +0100
From: Peter Hickman <peter@semantico.com>
Subject: Re: I am sure this was working so what's wrong now - help needed
Message-Id: <3f72c92f$0$10770$afc38c87@news.easynet.co.uk>

John wrote:
> $x=$1;$x=~s#One#Two#g;'href="'.$x.'"'/ei;

The i at the end of the line says 'this is case insensitive', you should 
remove it.



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

Date: Thu, 25 Sep 2003 11:02:34 GMT
From: "John" <none@none.com>
Subject: Re: I am sure this was working so what's wrong now - help needed
Message-Id: <eXzcb.122481$bo1.47678@news-server.bigpond.net.au>


"Peter Hickman" <peter@semantico.com> wrote in message
news:3f72c92f$0$10770$afc38c87@news.easynet.co.uk...
> John wrote:
> > $x=$1;$x=~s#One#Two#g;'href="'.$x.'"'/ei;
>
> The i at the end of the line says 'this is case insensitive', you should
> remove it.
>

Peter,

The /i does not seem to play a part here.
The problem is with writing the output to the file [does not work] as
opposed to the screen [which works if tried].




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

Date: Thu, 25 Sep 2003 12:15:30 +0100
From: Peter Hickman <peter@semantico.com>
Subject: Re: I am sure this was working so what's wrong now - help needed
Message-Id: <3f72ce52$0$10778$afc38c87@news.easynet.co.uk>

John wrote:
> "Peter Hickman" <peter@semantico.com> wrote in message
> news:3f72c92f$0$10770$afc38c87@news.easynet.co.uk...
> 
>>John wrote:
>>
>>>$x=$1;$x=~s#One#Two#g;'href="'.$x.'"'/ei;
>>
>>The i at the end of the line says 'this is case insensitive', you should
>>remove it.
>>
> 
> 
> Peter,
> 
> The /i does not seem to play a part here.
> The problem is with writing the output to the file [does not work] as
> opposed to the screen [which works if tried].
> 
> 

Ok I see what you mean.

###########################The below concerns me
         if ($_ =~ "A HREF=") {
             my $link = $_;
             $link =~ s/href="([^"]+)"/my
$x=$1;$x=~s#One#Two#g;'href="'.$x.'"'/ei;
         }
         (print NEW $_);
     }
###########################The above concerns me

Note that you started with the line in $_, which you copied into $link. You 
then modified $link but wrote out $_.

Try

if ($_ =~ "A HREF=") {
	$link =~ s/href="([^"]+)"/my $x=$1;$x=~s#One#Two#g;'href="'.$x.'"'/ei;
	print NEW $link;
} else {
	print NEW $_;
}



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

Date: 25 Sep 2003 11:31:07 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: I am sure this was working so what's wrong now - help needed
Message-Id: <bkujlr$ccl$1@mamenchi.zrz.TU-Berlin.DE>

John <none@none.com> wrote in comp.lang.perl.misc:
> 
> "Peter Hickman" <peter@semantico.com> wrote in message
> news:3f72c92f$0$10770$afc38c87@news.easynet.co.uk...
> > John wrote:
> > > $x=$1;$x=~s#One#Two#g;'href="'.$x.'"'/ei;
> >
> > The i at the end of the line says 'this is case insensitive', you should
> > remove it.
> >
> 
> Peter,
> 
> The /i does not seem to play a part here.
> The problem is with writing the output to the file [does not work] as
> opposed to the screen [which works if tried].

One problem with the original code is that you never write back the
changed value.  The relevant code again:

    if ($_ =~ "A HREF=") {
        my $link = $_;
        $link =~ s/href="([^"]+)"/my $x=$1;$x=~s#One#Two#g;'href="'.$x.'"'/ei;
    }
    (print NEW $_);

You change the text in $link, but you write back $_.  Apply the substitution
to $_ directly.  Mind, I didn't check if the substitution does what it
should do, but whatever it does, it won't end up in the file.

Anno



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

Date: Thu, 25 Sep 2003 11:43:27 GMT
From: "John" <none@none.com>
Subject: Re: I am sure this was working so what's wrong now - help needed
Message-Id: <zxAcb.122521$bo1.83286@news-server.bigpond.net.au>


"Peter Hickman" <peter@semantico.com> wrote in message
news:3f72ce52$0$10778$afc38c87@news.easynet.co.uk...
> John wrote:
> > "Peter Hickman" <peter@semantico.com> wrote in message
> > news:3f72c92f$0$10770$afc38c87@news.easynet.co.uk...
> >
> >>John wrote:
> >>
> >>>$x=$1;$x=~s#One#Two#g;'href="'.$x.'"'/ei;
> >>
> >>The i at the end of the line says 'this is case insensitive', you should
> >>remove it.
> >>
> >
> >
> > Peter,
> >
> > The /i does not seem to play a part here.
> > The problem is with writing the output to the file [does not work] as
> > opposed to the screen [which works if tried].
> >
> >
>
> Ok I see what you mean.
>
> ###########################The below concerns me
>          if ($_ =~ "A HREF=") {
>              my $link = $_;
>              $link =~ s/href="([^"]+)"/my
> $x=$1;$x=~s#One#Two#g;'href="'.$x.'"'/ei;
>          }
>          (print NEW $_);
>      }
> ###########################The above concerns me
>
> Note that you started with the line in $_, which you copied into $link.
You
> then modified $link but wrote out $_.
>
> Try
>
> if ($_ =~ "A HREF=") {
> $link =~ s/href="([^"]+)"/my $x=$1;$x=~s#One#Two#g;'href="'.$x.'"'/ei;
> print NEW $link;
> } else {
> print NEW $_;
> }
>

Yeah! Thanks heaps. I was looking at it for ages and tried fiddling with the
output but my lines in the new file were doubling up. Somehow I was
finishing up with one line which was the original and another which was the
replaced one. Thanks again Peter :c)





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

Date: Thu, 25 Sep 2003 12:08:21 GMT
From: "John" <none@none.com>
Subject: Re: I am sure this was working so what's wrong now - help needed
Message-Id: <VUAcb.122574$bo1.86372@news-server.bigpond.net.au>


"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:bkujlr$ccl$1@mamenchi.zrz.TU-Berlin.DE...
> John <none@none.com> wrote in comp.lang.perl.misc:
> >
> > "Peter Hickman" <peter@semantico.com> wrote in message
> > news:3f72c92f$0$10770$afc38c87@news.easynet.co.uk...
> > > John wrote:
> > > > $x=$1;$x=~s#One#Two#g;'href="'.$x.'"'/ei;
> > >
> > > The i at the end of the line says 'this is case insensitive', you
should
> > > remove it.
> > >
> >
> > Peter,
> >
> > The /i does not seem to play a part here.
> > The problem is with writing the output to the file [does not work] as
> > opposed to the screen [which works if tried].
>
> One problem with the original code is that you never write back the
> changed value.  The relevant code again:
>
>     if ($_ =~ "A HREF=") {
>         my $link = $_;
>         $link =~ s/href="([^"]+)"/my
$x=$1;$x=~s#One#Two#g;'href="'.$x.'"'/ei;
>     }
>     (print NEW $_);
>
> You change the text in $link, but you write back $_.  Apply the
substitution
> to $_ directly.  Mind, I didn't check if the substitution does what it
> should do, but whatever it does, it won't end up in the file.
>
> Anno
>

Thanks as well Anno. Sometimes those obvious things are the most difficult
to spot.
I amended the script to reflect Peter's suggestion and all is well now.




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

Date: 25 Sep 2003 11:00:41 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Mapping characters in a string
Message-Id: <bkuhsp$au8$1@mamenchi.zrz.TU-Berlin.DE>

Uri Guttman  <uri@stemsystems.com> wrote in comp.lang.perl.misc:
> >>>>> "AvC" == Alfred von Campe <alfred@110.net> writes:
> 
>   AvC> I must have a brain cramp today, because I can not figure out an
>   AvC> elegant way to do the following.  I have a 16 byte, binary MD5 digest
>   AvC> (generated with Digest::MD5) in one scalar, and another scalar
>   AvC> containing exactly 256 printable characters.  I want to create a
>   AvC> printable version of the MD5 digest by using the bytes of the digest
>   AvC> as an index into the string of printable characters.  I can do this in
>   AvC> a loop one byte at a time, but there must be a solution using map
>   AvC> and/or pack/unpack to do this more elegantly.  Any ideas?
> 
> slice to the (double) rescue!!
> 
> <untested>
> 
> my $encoded_md5 = join( '', (split //, $md5_map)[ split //, $md5_digest ] ) ;

There's an ord() missing.

   (split //, $md5_map)[ map ord, split //, $md5_digest ] ) ;


Alternatively:

    $_ = $md5_digest;
    eval "tr/\0-\xff/$md5_map/";
    $encoded_md5 = $_;

Extra points for why the dreaded string-eval is required here (and
absolutely harmless).  No, not you, Uri :)

> <aside to lame flamer>
> oh, borland, where is thy limp flame now? any answers from you?
> typical flame but no help.
> </aside to lame flamer>

Oh, come on, don't nettle her.  She may still come around.

Anno


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 5559
***************************************


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