[22747] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4968 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 10 06:05:59 2003

Date: Sat, 10 May 2003 03:05:09 -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           Sat, 10 May 2003     Volume: 10 Number: 4968

Today's topics:
    Re: Bloody Java Proselytisers!!! <fxn@hashref.com>
    Re: dont match this pattern <nobull@mail.com>
        Emacs modules for Perl programming (Jari Aalto+mail.perl)
    Re: How many groups have a regex? nobull@mail.com
    Re: How many groups have a regex? (i5513)
    Re: How to find the size of a directory??? (Jay Tilton)
    Re: In search of elegant code - calling subroutines wit <nobull@mail.com>
        IO:Select module Help! <nil@nil.com>
    Re: Logic(al nightmare!) <sammie@greatergreen.com>
    Re: Month number being returned is incorrect <jurgenex@hotmail.com>
    Re: Month number being returned is incorrect (J.B. Moreno)
    Re: Month number being returned is incorrect <jehoshua@my-deja.com>
    Re: Month number being returned is incorrect <jehoshua@my-deja.com>
    Re: Month number being returned is incorrect <tassilo.parseval@rwth-aachen.de>
        perl -pe "s/<er>/<er>\n"/g": memory efficient version? (Michael Wang)
    Re: perl -pe "s/<er>/<er>\n"/g": memory efficient versi (Jay Tilton)
    Re: perl -pe "s/<er>/<er>\n"/g": memory efficient versi (Jay Tilton)
    Re: perl -pe "s/<er>/<er>\n"/g": memory efficient versi <lvl@club-internet.fr>
    Re: regex patterns, match this and that in any order <nobull@mail.com>
        Splitting, Sorting, then Rebuilding an Array <sammie@greatergreen.com>
        Standard Error <musicman@hotmail.com>
    Re: Standard Error <nobull@mail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 10 May 2003 08:00:52 +0000 (UTC)
From: Xavier Noria <fxn@hashref.com>
Subject: Re: Bloody Java Proselytisers!!!
Message-Id: <b9ibjk$661$1@news.ya.com>

In article <87wugzlp4b.fsf@mithril.chromatico.net>, Charlton Wilbur wrote:

: William Goedicke <goedicke@goedsole.com> writes:
: 
:> > William Goedicke <goedicke@goedsole.com> writes:
:> > 
:> > > Of course, projects can be completed with mediocre programmers in any
:> > > language.  What characteristic does java have that makes it better at
:> > > this than other languages?
:> > 
:> > An enormous standard library
:> 
:> This doesn't strike me as a differentiating point from perl.
: 
: Except that to develop at all you have the JDK on your system, and to
: run Java at all you have the JRE.  Imagine if you knew you could use
: any module from CPAN, and you could ship code that relied on any
: module in CPAN, without having to worry about installing modules.

That's not the analogy.

Java comes with a library and perl comes with core modules. That is. I can
rely on FindBin or CGI.pm being there. Imagine on the contrary if you could
document the installation of non-standard libraries in Java applications as
easy as you do for Perl modules. Not to mention the programmatic download
and installation from an install script.

Java add-ons are scattered all over the web, packaged with no standard
structure. Perl on the other hand has CPAN.

:> Can't the mediocre programmer still play havoc by not doing adequate
:> file and socket error handling or input data validation?
: 
: The mediocre programmer can, yes.  But error handling in Java is most
: easily done with exceptions; if you don't check the error result, you
: get a stack dump with a FileNotOpen exception when you try to write to
: it.  Perl, by contrast, provides very good error messages, but you
: need to explicitly check them for them to do you any good.

No difference with Java too in my opinion. Now the Java programmer can catch
the exception or just throw it up as well. Or worst, he can eat everything
with a big try/catch(Throwable). I work in a Java-based company and
exception handling is rarely done right, because it requires discipline and
a good design in that regard.

The language is not the solution, it is the people.

:> Generically isn't the existance of so many buggy and poor performing
:> programs written in java an empirical proof that it doesn't preclude
:> bad programming practices?
: 
: My point is not that you can't do bad programming in Java, but that it
: provides a tremendous amount of support to prevent the worst
: programming practices.  If you make something foolproof, then a damn
: fool will break it all the same; but if you can eliminate most of the
: problem areas, you can then get semi-fools to do the work.

That's an illusion IMO. You add type-checking and that way you prevent type
errors (well, if we assume the forthcoming generics, because otherwise any
serious Java application uses collections and is full of casts). But how do
you measure the bugs introduced by the verbosity? By the bigger amount of
code needed? How do you measure the negative effect of decreasing in team
productivity, creativity, and fun due to the bondage and discipline? I think
mediocre managers get an appealing message "hey, that project compiles so at
least types are OK" which sounds good, but in my opinion that's vapour.

-- fxn


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

Date: 10 May 2003 07:41:58 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: dont match this pattern
Message-Id: <u9brybnw09.fsf@wcl-l.bham.ac.uk>

Brian McCauley <nobull@mail.com> writes:

> s/(match this)(.*)(match this)(?(?{$2!~m{exclude this}})|(?!))/something/;

Actually that's rather inefficient, probably better to reverse two of
the bits.

s/(match this)(.*)(?(?{$2!~m{exclude this}})|(?!))(match this)/something/;

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


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

Date: 10 May 2003 08:27:58 GMT
From: <jari.aalto@poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_1052555163@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 <jari.aalto@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.
            XEmacs port is bundled in XEmacs setup.exe available from
            XEmacs site.

        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

        ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
        http://www.perl.com/CPAN-local/misc/emacs/cperl-mode/
        <ilya@math.ohio-state.edu>    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@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: 10 May 2003 01:30:24 -0700
From: nobull@mail.com
Subject: Re: How many groups have a regex?
Message-Id: <4dafc536.0305100030.67e52647@posting.google.com>

Brian McCauley <nobull@mail.com> wrote in message news:<u93cjow0oo.fsf@wcl-l.bham.ac.uk>...
> 
> scalar(@+) or scalar(@-)

Oops, off by one.

$+[0] and $-[0] refer to $&
$+[1] and $-[1] refer to $1
  and so on...

So the number of captures is (@+ - 1) or $#+

Actually  $#+ is supposed to return the number of catuptures in the
regex, and $#- the index of the highest capture that actually
captured.

This is, however, slightly buggy.

'' =~ /()|(.)/ ; $#- = 1    -- correct
'' =~ /()(.)?/ ; $#- = 2    -- wrong


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

Date: 10 May 2003 02:43:42 -0700
From: i5513@hotmail.com (i5513)
Subject: Re: How many groups have a regex?
Message-Id: <a657ec02.0305100143.18339630@posting.google.com>

> Why not do the match in list context and use an array rather than a
> hash.  
Ok, I wrote { and I wanted to write 
The array @groups can be built without using $n_groups.  It even
 works under stricture.
> 
> use strict;
> use warnings;
> my $str = 'a b c';
> my $pat = '(a) (b) (c)';
> my @group = ();
> push @group, $_ foreach ($str=~/$pat/);
> print join "\n", @group;
> 
> 
Bill, if you change $pat by '(a)(b)((c)|(d))', @group isn't a copy of "@i" array.
The problem is solved. Thank you


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

Date: Sat, 10 May 2003 04:24:43 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: How to find the size of a directory???
Message-Id: <3ebc7ee6.2574469@news.erols.com>

"Bigus" <bigus AT creationfactor DOT net> wrote:
: "Helgi Briem" <helgi@decode.is> wrote in message
: news:3ebb8c6f.2492301740@news.cis.dfn.de...
: > On Fri, 9 May 2003 11:52:12 +0100, "Bigus" <bigus AT
: > creationfactor DOT net> wrote:
: >
: > >> Jürgen Exner wrote:
: > >> > Or do you mean the size of all files in this directory and
: recursively
: > >> >all sub directories? Then have a look at File::Find. In the wanted()
: > >> >function just add the size of each file (from -s) in a global
: variable.
: >
: > >or if it's Windows, then issue a DIR command and extract the
: > >total size from the 2nd to last line of it's output ;-)
: >
: > That will only work for one directory level.  Juergen's
: > suggestion to use File::Find is still the best suggestion
: > (by far).
: 
: Yes, probably. DIR would work though:
: 
: DIR d:\mydir\*.* /s
: 
: /s meaning include all subdirectories.

Or...

    use Win32::OLE;
    print Win32::OLE->new('Scripting.FileSystemObject')
        ->GetFolder('c:\some_dir')->Size;



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

Date: 10 May 2003 07:50:07 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: In search of elegant code - calling subroutines within a match?
Message-Id: <u97k8znvmo.fsf@wcl-l.bham.ac.uk>

Gunnar Hjalmarsson <noreply@gunnar.cc> writes:

> David Filmer wrote:

> >    s/xyz/&bar()/;   #change "xyz" to the output of &bar() in one
> > statement

> Add the /e modifier:
> 
>      s/xyz/bar()/e;
> ----------------^

The /e is usually the right way but sometimes it is more elegant to
use the @{[]} syntax.  Note this will call bar() in a list
context.

s/xyz/'This ' . bar() . ' that'/e;
s/xyz/This @{[ bar() ]} that/;

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


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

Date: Sat, 10 May 2003 04:33:35 GMT
From: J <nil@nil.com>
Subject: IO:Select module Help!
Message-Id: <820pbv4dkat00qq7gqhusgl1tk3bh8nqnm@4ax.com>

Hi,

I have setup to listening sockets, one a UDP one and another TCP one.  I need to use the
Select method to listen for data on each of these.  I have the following so far:

#!/usr/bin/perl -w

use IO::Socket;
use IO::Select;


# Read config file and store in array
my @config;
open (CONFIG, "config.txt") or die "I couldn't open server config file";
@config = <CONFIG>;
close CONFIG;


my $wb_server_port = $config[0];
my $lc_server_port = $config[1];
my $ig_host_name = $config[4];
my $ig_port = $config[5];
my $ig_username = $config[6];
my $ig_password = $config[7];

my $wb_listener = IO::Socket::INET->new(LocalPort => $wb_server_port,
                                   Proto => "tcp",
                                   Listen => 250 )
                         or die "Couldn't be a web server on port $wb_server_port : $@\n";


my $lc_listener = IO::Socket::INET->new(LocalPort => $lc_server_port,
                                   Proto => "udp")
                or die "Couldn't be a log client server on port $lc_server_port : $@\n";


my $select = IO::Select->new($wb_listener);
$select->add($lc_listener);


I would like to know how I now go about testing for and handling the incoming data for
each of the listeners.  

Cheers



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

Date: Sat, 10 May 2003 09:33:35 GMT
From: "Brad Walton" <sammie@greatergreen.com>
Subject: Re: Logic(al nightmare!)
Message-Id: <PH3va.791866$3D1.440004@sccrnsc01>

> Even without doing anything about the global variables floating
> around, the code can be shorter and clearer by using 'next' and a few
> statement modifiers:
>
>
> sub file_stats_left {
>     my @DB;
>     tie @DB, 'Tie::File', $dormantstatdb
>         or die "cannot open $dormantstatdb: $!\n";
>     for my $db (@DB) {
>         my $name = (split /\t/, $db)[1];
>         foreach my $discpl (@discpl) {
>             next unless $discpl eq $name;
>             foreach my $oldsession (@oldsession) {
>                 $db = $oldsession if $oldsession =~ /$name/;
>             }
>             $added{$discpl} = 1;
>         }
>     }
>
>     foreach my $discpl (@discpl) {
>         next if $added{$discpl};
>         foreach my $oldsession (@oldsession) {
>             push @DB, $oldsession if $oldsession =~ /$discpl/;
>         }
>     }
>
>     untie @DB;
> }

Thank you David. That is much cleaner, and I learned a lot from it. I
replaced it in my program and it is now working very well. I appreciate the
time.

I do have a follow-up question: Some of those variables do work in other
subroutines, and while it was not intentional, having them global made
passing them from subroutines very easy.

Is there a way to pass a:  my ($variable or @array) beyond its subroutine?
Will:  return($variable or @array); work?
And does that in turn need to be passed to the next subroutine with:
&sub_routine($variable or @array)?

Brad




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

Date: Sat, 10 May 2003 04:45:26 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Month number being returned is incorrect
Message-Id: <Gt%ua.1037$TM6.975@nwrddc02.gnilink.net>

Peter Richards wrote:

> [Subject]
No, it is not. It returns the correct value just as specified in the
documentation.

[...]
> and I read somewhere that the month value returned by localtime is 0
> to 11,

I hope you read it in "perldoc -f localtime"?

> and that is what the problem is, a (flat) file created in May
> will have month value of 4.

Which is the correct value as defined in the spec.

> How do I increment the variable $month by 1 ? Is it just:
>
>     $month++;

That would be one possibility.
Or you could do
    $month += 1;
Or
    $month = $month + 1;
Or, or, or....

jue




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

Date: Sat, 10 May 2003 01:22:26 -0400
From: planB@newsreaders.com (J.B. Moreno)
Subject: Re: Month number being returned is incorrect
Message-Id: <1fupyg0.i3r6ya1r77517N%planB@newsreaders.com>

Peter Richards <jehoshua@my-deja.com> wrote:

> my (undef, undef, undef, $day, $month, $year, @rest) =
> localtime(time); 
-snip- 
> How do I increment the variable $month by 1 ? Is it just:
> 
>     $month++;

Yes.


-- 
JBM
"Everything is futile." -- Marvin of Borg


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

Date: Sat, 10 May 2003 16:07:28 +1000
From: Peter Richards <jehoshua@my-deja.com>
Subject: Re: Month number being returned is incorrect
Message-Id: <vs4pbv422n3rbldt7o417hi4fatet1glmd@4ax.com>

Hi Jue,

On Sat, 10 May 2003 04:45:26 GMT, "Jürgen Exner"
<jurgenex@hotmail.com> wrote:

>Peter Richards wrote:
>
>> [Subject]
>No, it is not. It returns the correct value just as specified in the
>documentation.

Yes, you are correct, I should have made the subject "Month number
being returned is not what I want', or something else.

>[...]
>> and I read somewhere that the month value returned by localtime is 0
>> to 11,
>
>I hope you read it in "perldoc -f localtime"?

No, some web discussion forum, but I can see now in the 'ActivePerl'
docs, all the details about localtime, very interesting.

>> and that is what the problem is, a (flat) file created in May
>> will have month value of 4.
>
>Which is the correct value as defined in the spec.

Yes, using a base of zero, my problem was I assumed it would use a
base of 1, and of course I needed a value of 5 for May !  :)

>> How do I increment the variable $month by 1 ? Is it just:
>>
>>     $month++;
>
>That would be one possibility.
>Or you could do
>    $month += 1;
>Or
>    $month = $month + 1;

Thanks for your help,

Peter


Peter Richards
peter_j_richards@nospamplease.com
 (but use hotmail to email)


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

Date: Sat, 10 May 2003 16:24:12 +1000
From: Peter Richards <jehoshua@my-deja.com>
Subject: Re: Month number being returned is incorrect
Message-Id: <rg6pbvsfb5cpjdiq5uge2c6uhr3r7okemi@4ax.com>

Hi,

On Sat, 10 May 2003 01:22:26 -0400, planB@newsreaders.com (J.B.
Moreno) wrote:

>Peter Richards <jehoshua@my-deja.com> wrote:
>
>> my (undef, undef, undef, $day, $month, $year, @rest) =
>> localtime(time); 
>-snip- 
>> How do I increment the variable $month by 1 ? Is it just:
>> 
>>     $month++;
>
>Yes.

Thanks, BTW, there are Perl scripts with code like:

$month = MONTH ++$month;

Is this just a method to double the value , or is it yet another
method to increment ?

Peter


Peter Richards
peter_j_richards@nospamplease.com
 (but use hotmail to email)


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

Date: 10 May 2003 06:56:29 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Month number being returned is incorrect
Message-Id: <b9i7qt$9n1$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Peter Richards:

> Thanks, BTW, there are Perl scripts with code like:
> 
> $month = MONTH ++$month;
> 
> Is this just a method to double the value , or is it yet another
> method to increment ?

No, it's a method to create a syntax-error. Where did you pick this up?
If MONTH is actually a subroutine defined before the above line, it
could have some meaning and even compile.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Sat, 10 May 2003 05:09:51 GMT
From: mwang@unixlabplus.com (Michael Wang)
Subject: perl -pe "s/<er>/<er>\n"/g": memory efficient version?
Message-Id: <zQ%ua.194$yr1.73745@news.uswest.net>

I have a file which has 1 super long line that contains

some thing<er>something else<er>and more stuff<er>...

perl -pe "s/<er>/<er>\n"/g"

works for small files, but for large files, it runs out of
memory. Is there a memory efficient version?

awk '{gsub("<er>","<er>\n"); print}'
is not memory efficient either.

Any solution using standard Unix utility is welcome,
(without having to code a control character).

Thanks.
-- 
Michael Wang * http://www.unixlabplus.com/ * mwang@unixlabplus.com


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

Date: Sat, 10 May 2003 05:18:01 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: perl -pe "s/<er>/<er>\n"/g": memory efficient version?
Message-Id: <3ebc8b2c.5717784@news.erols.com>

mwang@unixlabplus.com (Michael Wang) wrote:

: I have a file which has 1 super long line that contains
: 
: some thing<er>something else<er>and more stuff<er>...
: 
: perl -pe "s/<er>/<er>\n"/g"
: 
: works for small files, but for large files, it runs out of
: memory. Is there a memory efficient version?

    perl -lpe "BEGIN{$/='<er>'}" foo.txt



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

Date: Sat, 10 May 2003 05:24:20 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: perl -pe "s/<er>/<er>\n"/g": memory efficient version?
Message-Id: <3ebc8c89.6066314@news.erols.com>

tiltonj@erols.com (Jay Tilton) wrote:

: mwang@unixlabplus.com (Michael Wang) wrote:
: 
: : I have a file which has 1 super long line that contains
: : 
: : some thing<er>something else<er>and more stuff<er>...
: : 
: : perl -pe "s/<er>/<er>\n"/g"
: : 
: : works for small files, but for large files, it runs out of
: : memory. Is there a memory efficient version?
: 
:     perl -lpe "BEGIN{$/='<er>'}" foo.txt

I should have tested that first.  I forgot about the auto-chomp()
behavior with that combination of switches.

    perl -pe "BEGIN{$\=$/;$/='<er>'}" foo.txt



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

Date: Sat, 10 May 2003 10:18:14 +0200
From: "Laurent Vogel" <lvl@club-internet.fr>
Subject: Re: perl -pe "s/<er>/<er>\n"/g": memory efficient version?
Message-Id: <3ebcb5c6$0$14317$7a628cd7@news.club-internet.fr>


"Michael Wang" <mwang@unixlabplus.com> a écrit dans le message de news:
zQ%ua.194$yr1.73745@news.uswest.net...
> I have a file which has 1 super long line that contains
>
> some thing<er>something else<er>and more stuff<er>...
>
> perl -pe "s/<er>/<er>\n"/g"
>
> works for small files, but for large files, it runs out of
> memory.
>
> Any solution using standard Unix utility is welcome.

use tr to replace any > by a newline, then post-process with sed.

Laurent




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

Date: 10 May 2003 08:17:15 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: regex patterns, match this and that in any order
Message-Id: <u93cjnnudg.fsf@wcl-l.bham.ac.uk>

stinkbomb <user@someserver123abc.com> writes:


> $var="(a)(b)(c=d)(e$%f)";
> $var=~ s/\((.*?=.*?)\)/\[$1\]/g; #this doesn't work
> print $var;
> 
> get name=value pair that's inside the ()
> put it inside < and > so that we have (<c=d>)

I shall assume the discrepency between [] and () is just a typo.

Even subexpressions with non greedy qualifiers mach the leftmost match.

  $var=~ s/\((\w+=.*?)\)/[$1]/g;


> (match '(' )     (  match '=' but not '(' or ')' )       ( match ')' )
> and do this for every (...)
> and we have four (...)

I have no idea how those factured statements fit into this.

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


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

Date: Sat, 10 May 2003 09:25:42 GMT
From: "Brad Walton" <sammie@greatergreen.com>
Subject: Splitting, Sorting, then Rebuilding an Array
Message-Id: <qA3va.791823$3D1.439874@sccrnsc01>

This has got to be the hard way to write this... If you know of a more
efficient way, it would be appreciated:

sub sort_by_name {
 my $rebuild;

 #Grab data and sort by callsign
 foreach $archivedata (@archivedata) {
  my
($sess,$cals,$plid,$mapid,$tcur,$tcon,$scor,$stat,$eak,$esak,$etk,$eck,$eatk
,$eaaak,$ewk,$esp,$fak,

$fsak,$ftk,$fck,$fatk,$faaak,$fwg,$fsp,$fb,$hb,$hab,$fr,$hr,$fbmb,$hbmb,$ipa
d,$ctry,$empty,$emptyy) = split /\t/, $archivedata;
  $cals =~ tr/a-z/A-Z/;
  $rebuild =
"$sess\t$cals\t$plid\t$mapid\t$tcur\t$tcon\t$scor\t$stat\t$eak\t$esak\t$etk\
t$eck\t$eatk\t$eaaak\t$ewk\t$esp\t$fak\t$fsak\t$ftk\t$fck\t$fatk\t$faaak\t$f
wg\t$fsp\t$fb\t$hb\t$hab\t$fr\t$hr\t$fbmb\t$hbmb\t$ipad\t$ctry\t$empty\t$emp
tyy";
  @formateddata = (@formateddata,$rebuild);
 }
 @formateddata = sort(@formateddata);
}

Thanks for any help,
Brad




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

Date: Sat, 10 May 2003 09:10:38 +0200
From: Music Man <musicman@hotmail.com>
Subject: Standard Error
Message-Id: <MPG.1926c45dff4ab252989704@news.siol.net>

Hi !

I have a Linux-Perl application, which is started from INET daemon.
It redirects standard input to socket.

#!/usr/local/bin/perl
use strict;
use IO::Handle ;
use IO::Socket ;

my $tmpsocket=IO::Socket->new_from_fd(\*STDIN,"+<") or 
   die "Cannot create socket: $@\n";
my $connect=getpeername($tmpsocket);
my ($port,$hisaddr)=sockaddr_in($connect);
my $IP=inet_ntoa($hisaddr);
autoflush STDIN 1 ;

print "This goes to the connector:\n";
my $DATA="";
my $FLAGS=0 ;
my $PORT=recv($tmpsocket,$DATA, 160, $FLAGS) ;

 ....etc...

The problem is that when some internal programming error occurs (like 
calling a invalid function), the remote host get this message.
Is there any chance, to redirect all perl error messages to somewhere 
else ? I don't know even, if it displays them on stderr, or stdout.


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

Date: 10 May 2003 08:20:22 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Standard Error
Message-Id: <u9y91fmfnt.fsf@wcl-l.bham.ac.uk>

Music Man <musicman@hotmail.com> writes:

> Is there any chance, to redirect all perl error messages to somewhere 
> else ?


open(STDERR,'>','whereever you want your errors')

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


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

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


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