[31235] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2480 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 16 21:09:42 2009

Date: Tue, 16 Jun 2009 18:09: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           Tue, 16 Jun 2009     Volume: 11 Number: 2480

Today's topics:
    Re: cannot solve a memory leak sln@netherlands.com
    Re: cannot solve a memory leak sln@netherlands.com
    Re: FAQ 2.11 Perl Books <cartercc@gmail.com>
    Re: FAQ 2.11 Perl Books <brian.d.foy@gmail.com>
    Re: FAQ 2.11 Perl Books <cartercc@gmail.com>
    Re: format the multiselect option froma web form <tadmc@seesig.invalid>
    Re: format the multiselect option froma web form <hjp-usenet2@hjp.at>
    Re: Lexical variables in (?{...}) regexp constructs <ala.netstuff@gmail.com>
    Re: Lexical variables in (?{...}) regexp constructs sln@netherlands.com
    Re: Lexical variables in (?{...}) regexp constructs sln@netherlands.com
    Re: Lexical variables in (?{...}) regexp constructs sln@netherlands.com
        sort array of string with tab separated items <jcharth@gmail.com>
    Re: sort array of string with tab separated items <jurgenex@hotmail.com>
    Re: sort array of string with tab separated items <nn@nn.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 16 Jun 2009 11:58:29 -0700
From: sln@netherlands.com
Subject: Re: cannot solve a memory leak
Message-Id: <depf35hmendbpp6kv4mvjj4nfl0dqt56a5@4ax.com>

On Tue, 16 Jun 2009 01:33:50 -0700 (PDT), Sébastien Cottalorda <scottalorda@libello.com> wrote:

>Hi all,
>I develop an program based on a module names 'SHM' based on
>IPC::Shareable module.
>I'm under Fedora core 9 (kernel 2.6.27.21-78.2.41.fc9.i686)   with
>Perl 5.10.0
>
>it works like this:
>
>IPC::Shareable  does this when it try to get something in memory
>segment:
>--------------------------------------------------------------------------
>sub FETCH {
>    [snip]
>    my $data;
>    if ($self->{_lock} || $self->{_iterating}) {
>        $self->{_iterating} = ''; # In case we break out
>        $data = $self->{_data};
>    } else {
>        $data = _thaw($self->{_shm});
>        $self->{_data} = $data;
>    }
>    my $val;
>    [snip]
>    # work with $data following $self->{_type} type => then put result
>in $val variable
>    return $val
>}
>....
>sub _thaw {
>[snip]
>my $s = shift;
>my $ice = $s->shmread;
>my $tag = substr $ice, 0, 14, '';
>if ($tag eq 'IPC::Shareable') {
>        my $water = thaw $ice;       # imported from Storable module
>        defined($water) or do {
>            require Carp;
>            _debug "Prob into shm segment ", $s->id, ": ", $ice;
>            Carp::confess "Munged shared memory segment (size
>exceeded?) into shm segment ";
>        };
>        return $water;
>} else {
>        return;
>}
>----------------------------------------------------------------------------------
>my module, 'SHM', based on IPC::Shareable module does this
>sub get_hash {
>    my $this = shift;
>    my $type    = ref($this) or croak "GET: $this is not an object";
>    my $hashref = shift;
>    my %datas = ();
>    eval {
>        %datas = %{$this->{_data}};    # line 537 on which I got
>Munged share memory .... message
>    };
>    if ($@){
>        croak "GET: Unable to get ".$hashref->{type}."| segment
>allKeys : $@";
>    }
>    else {
>        [snip]
>    }
>}
>---------------------------------------------------------------------------------------------------------
>my program base on the 'SHM' module does this
>[snip]
>my $memCmd = 'ps axfv | grep -P "^\s{0,}'.$$.'" | grep -v grep ';
>print "MEMSize (BEFORE)=". `$memCmd` ;
>if ($SEGMENT->shlock(LOCK_SH)){
>    eval {
>        $pano_SHM 	= $SEGMENT->get_hash({ type => 'panneau', primary
>=> $control });
>    };
>    if ($@){
>        [snip]
>    }
>    print "MEMSize (AFTER)=". `$memCmd` ;
>}
>else {
>    print "unable to get a lock on SHM\n";
>}
>
>I run several time (5 times), in parallel, the same program.
>I have then concurrent access to the memory segment.
>On concurrent access, one process get the error :
>"Munged shared memory segment (size exceeded?) into shm segment"
>I note then that the virtual memory grow till 1,8 Go for the process
>on which occured the access problem.
>I trace this:
>
>MEMSize (BEFORE)= 5080 pts/7    S+    17:47      0     3 13776  8992
>0.2          \_ PK52
>"Munged shared memory segment (size exceeded?) into shm segment" at
>SHM line 537
>MEMSize (AFTER)= 5080 pts/7    S+    17:47      0     3 1849624 9832
>0.2          \_ PK52
>
>If someone can help me in solving this problem , make me add some
>useful trace somewhere, or whatever else .
>Thanks in advance.
>
>Sebastien


I'm not sure of what version your using. The latest on CPAN seems to
be version 0.60 @ 2001, that does sub-ties on references.

It looks in your usage like you have derived from IPC::Shareable.
Also, there might be a conflict with Perl 5.10, I don't know.

There is no indication how you instantiated your derived class
but you can't even get an object without doing
  tie $variable, 'IPC::Shareable', 'data', \%options;
somewhere in your constructor.

  you> I have then concurrent access to the memory segment.

I don't know how that is true from your example. I don't actually
see you using 'tied' type acess to that variable.

Instead, you are reading from a temporary variable in the objects
hash:  {_data}, used to read/write to shared memory.

But you are only reading from from shared memory with the lock.
You never unlock it, which would write it out:

	locking reads shared memory to _data:
	$self->{_data} = _thaw($self->{_shm})

	Unlocking writes _data to shared memory:
	_freeze($self->{_shm} => $self->{_data}

Unfortunately, by doing this directly, you are circumventing the 'tied' mechanisms
of update with its magic, and sub-tie (_mg_tie).

There is a debug mechanism if you want to use it:

	use constant DEBUGGING     => ($ENV{SHAREABLE_DEBUG} or 0);
	_debug() if DEBUGGING;

Version info:
$VERSION = 0.60;
0.60 Mon Mar 5 15:20:18 EST 2001 
Lee Lindley (lee.lindley@bigfoot.com) added the waschanged optimization,
improved the locking functionality, fixed numerous bugs, and generally cleaned
things up; thanks. 
This version of IPC::Shareable does not understand the format of shared memory segments
created by versions prior to 0.60. If you try to tie to such segments, you will get an error. 

These are just my observations as its the first time i've looked at it.

Hope this helps.
Ps. If you reply, snip out the content of non-interrest.

-sln



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

Date: Tue, 16 Jun 2009 12:08:25 -0700
From: sln@netherlands.com
Subject: Re: cannot solve a memory leak
Message-Id: <cbrf359s3s0d9fgs64qr8kpaa4ko8fasmh@4ax.com>

On Tue, 16 Jun 2009 11:58:29 -0700, sln@netherlands.com wrote:

>On Tue, 16 Jun 2009 01:33:50 -0700 (PDT), Sébastien Cottalorda <scottalorda@libello.com> wrote:
>
[snip]

But I don't know what version sharable this is using.


http://kobesearch.cpan.org/htdocs/IPC-Shareable/README.html

Known Problems
--------------------
2. Running out of shared memory 

make test may fail with the message 

Munged shared memory segment (size exceeded?) 

This is likely because the tests are exceeding the maximum size of a shared memory
segment (SHMMAX) or the system-wide limit on shared memory size (SHMALL).
The only solution is to increase SHMMAX and/or SHMALL for the system.
Consult your system documentation for how to do this. 

This failure could also mean that IPC::Shareable doesn't like your version of Storable
(IPC::Shareable makes some assumptions about the structure of serialized data).
This message would happen, for instance, when version 0.53 of IPC::Shareable was used
in conjunction with 1.0.x versions of Storable. If you're having problems, try using
Storable 1.0.7 which is known to work with IPC::Shareable 0.54. 



-sln



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

Date: Tue, 16 Jun 2009 07:44:48 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: FAQ 2.11 Perl Books
Message-Id: <c55cd9b4-0bba-47f0-9d59-b0642f8c80c8@u9g2000prd.googlegroups.com>

I have found the following very helpful. It blends Apache, CGI,
databases, and Perl for web enabled applications. It's not an entry
level book, as it assumes knowledge of references, but it's not an OO
book.

MySQL and Perl for the Web, Paul DuBois, New Riders, ISBN
0-7357-105406.

CC


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

Date: Tue, 16 Jun 2009 11:40:33 -0500
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 2.11 Perl Books
Message-Id: <160620091140335693%brian.d.foy@gmail.com>

In article
<c55cd9b4-0bba-47f0-9d59-b0642f8c80c8@u9g2000prd.googlegroups.com>,
ccc31807 <cartercc@gmail.com> wrote:

> MySQL and Perl for the Web,

Surely out-of-date by now, being 8 years old.


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

Date: Tue, 16 Jun 2009 11:24:10 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: FAQ 2.11 Perl Books
Message-Id: <9c4e9512-23fc-453a-a7fc-ae12aec63f6b@y7g2000yqa.googlegroups.com>

On Jun 16, 12:40=A0pm, brian d  foy <brian.d....@gmail.com> wrote:
> ccc31807 <carte...@gmail.com> wrote:
> > MySQL and Perl for the Web,
>
> Surely out-of-date by now, being 8 years old.

Conjecture, opinion, or fact? Besides which, Data Munging with Perl is
(c) 2001, while MySQL and Perl for the Web is (c) 2002.

The book is more out of date for Apache and MySQL than it is for Perl
and DBI, and besides, the techniques haven't changed. I mostly use
Postgres now instead of MySQL, but that doesn't mean that the book is
valueless being MySQL specific. DBI is still mostly the same, and you
interface with DBI, not the database.

Paul Dubois keeps the code up to date. I noticed recently that he had
replaced ImageMagick with something else in the section on graphics
manipulation.

I'm not going to suggest that you read the book. I will suggest that
you refrain from commenting on it until you have read it.

CC



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

Date: Tue, 16 Jun 2009 06:35:23 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: format the multiselect option froma web form
Message-Id: <slrnh3f0od.gdg.tadmc@tadmc30.sbcglobal.net>

Vit <finar76@gmail.com> wrote:
> On 15 Giu, 21:13, Tad J McClellan <ta...@seesig.invalid> wrote:
>> Vit <fina...@gmail.com> wrote:
>> > I have a .cgi that read the value from a "multiselect option list" and
>>
>> Where your data comes from is not relevant to your question,
>> so it should not be included in your question.
>>
>> Have you seen the Posting Guidelines that are posted here frequently?
>>
>> > I get the following results:
>>
>> > $VAR1 = '1-option1';
>> > $VAR2 = '3-option3';
>> > $VAR3 = '5-option5';
>>
>> Where is your code that makes that output?
>>
>> You should try to make a short and complete program *that we can run*
>> that illustrates your problem.

>> Note that my answer makes no mention of the CGI environment, because
>> where the data comes from does not matter to the solution.
>>
>> ------------------
>> #!/usr/bin/perl
>> use warnings;
>> use strict;
>>
>> my @interest = qw/ 1-option1 3-option3 5-option5 /;
>>
>> my %selected;
>> foreach my $opt ( 'option1' .. 'option6' ) {
>>     if( grep /$opt/, @interest ) {
>>         $selected{$opt} = 'selected';
>>     }
>>     else {
>>         $selected{$opt} = 'not selected';
>>     }
>>
>> }
>>
>> print "$_: $selected{$_}\n" for sort keys %selected;
>> ------------------
>>
>> --
>> Tad McClellan
>> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


It is bad manners to quote a .sig.

It is bad manners to quote an entire article.

It is bad manners to not interleave your comments following the
quoted text that you are going to comment on.

Have you seen the Posting Guidelines that are posted here frequently?


> sorry for that...


Sorry for what?

Including where your data comes from when where your data comes
from does not matter?

Not reading the Posting Guidelines for the group?

Not making a short and complete program that we can run?

Had you put your comment following the quoted text that you are
sorry for, then readers would know what you are sorry for...


> I'm just reading a multiselection


When I said "where the data come from is irrelevant" did you 
understand what I was saying?


> my @interest = $query->param("interest");  (an array with the result
> of the multiselection)


We cannot run this code because it contains a syntax error.

_You_ should try running it from the command line to test it
before subjecting hundreds of other people to it.

Your code puts 3 strings into @interest.

My code puts the same 3 strings into @interest.

Where the data comes from is irrelevant to answering your question.


> print MAIL Dumper @interest; (generate the text of en email)


More bogglement.

Do you plan to continue to debug CGI programs by sending yourself
debugging messages in email?


> what I'd like to "format" is the text of the email...


My code that you quoted above does that.

So why are you here again?

Did you even try running the code I posted?

My code makes output to STDOUT. It is assumed that if you want
the output to go somewhere else, then you will modify the posted
code to arrange for the output to go somewhere else.

    print MAIL "$_: $selected{$_}\n" for sort keys %selected;


> thanks all


Yeah, right.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Tue, 16 Jun 2009 19:05:11 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: format the multiselect option froma web form
Message-Id: <slrnh3fk68.81s.hjp-usenet2@hrunkner.hjp.at>

On 2009-06-16 06:03, Vit <finar76@gmail.com> wrote:
> print MAIL Dumper @interest; (generate the text of en email)

Read the documentation of Data::Dumper and play around with the Dumper
function to understand what it does.

	hp


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

Date: Tue, 16 Jun 2009 12:03:48 -0700 (PDT)
From: Ala <ala.netstuff@gmail.com>
Subject: Re: Lexical variables in (?{...}) regexp constructs
Message-Id: <90f9206e-264a-4b31-98fc-86df4bad572b@d25g2000prn.googlegroups.com>

On Jun 15, 5:00=A0pm, s...@netherlands.com wrote:

> Probably the key phrase is "the Perl code contained in these blocks";
> Imbedding code inside of a regular expression really has limited use
> unless used in conjunction with a conditional or to immediatly store
> the value of the last capture group.

Thanks for the reply. I realize my post wasn't very informative, and
that I'm probably playing with fire :)
Storing the last captured match is exactly what I'm using this
construct for. The basic idea is that I created a module to help parse
some non-trivial file format. The constructor of this module allows
the user to specify which parts of each record to capture and into
which variable to put it. It returns a compiled regexp that the user
can use when parsing. Something like this contrived example:

  use R;
  my ($name, $x, $y);
  my $rgx =3D R->new(-capture =3D> {
                                name =3D> \$name,
                                locx =3D> \$x,
                                locy =3D> \$y,
                               });

  #... later on .. use $rgx ..
  while (<$fh>) {
    if (/$rgx/) {
      print "$name is at ($x, $y).\n";
    }
  }

I used this module as part of a larger module, let's call it M, that
parses the whole file and defines some other methods to manipulate the
data.
For the most part, this works perfectly well. Weird things start to
happen, seemingly in a random fashion, when I instantiate module M
multiple times in a loop.

I guess I shouldn't be relying on experimental features, but since the
docs mentioned a work-around, I was curious.

Thanks,
--Ala



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

Date: Tue, 16 Jun 2009 14:12:25 -0700
From: sln@netherlands.com
Subject: Re: Lexical variables in (?{...}) regexp constructs
Message-Id: <l40g351q4vb170flkddi0o3ernvonagjct@4ax.com>

On Tue, 16 Jun 2009 12:03:48 -0700 (PDT), Ala <ala.netstuff@gmail.com> wrote:

>On Jun 15, 5:00 pm, s...@netherlands.com wrote:
>
>> Probably the key phrase is "the Perl code contained in these blocks";
>> Imbedding code inside of a regular expression really has limited use
>> unless used in conjunction with a conditional or to immediatly store
>> the value of the last capture group.
>
>Thanks for the reply. I realize my post wasn't very informative, and
>that I'm probably playing with fire :)
>Storing the last captured match is exactly what I'm using this
>construct for. The basic idea is that I created a module to help parse
>some non-trivial file format. The constructor of this module allows
>the user to specify which parts of each record to capture and into
>which variable to put it. It returns a compiled regexp that the user
>can use when parsing. Something like this contrived example:
>
>  use R;
>  my ($name, $x, $y);
>  my $rgx = R->new(-capture => {
>                                name => \$name,
>                                locx => \$x,
>                                locy => \$y,
>                               });
>
>  #... later on .. use $rgx ..
>  while (<$fh>) {
>    if (/$rgx/) {
>      print "$name is at ($x, $y).\n";
>    }
>  }
>
>I used this module as part of a larger module, let's call it M, that
>parses the whole file and defines some other methods to manipulate the
>data.
>For the most part, this works perfectly well. Weird things start to
>happen, seemingly in a random fashion, when I instantiate module M
>multiple times in a loop.
>
>I guess I shouldn't be relying on experimental features, but since the
>docs mentioned a work-around, I was curious.
>
>Thanks,
>--Ala

As far as I know, lexicals scoped within the block that initiates the
regex, should be ok, be it a reference or not (haven't tried it but assume its ok).
pseudo - example:
SCOPE:
{
	my ($name, $x, $y);
	my ($ref_name, $ref_x, $ref_y) = (\$name, \$x, \$y);

	my $rgx = qr/([a-z,A-Z]+)(?{$$name = $^N})(\d\d)(?{$$x = $^N}),(\d\d)(?{$$y = $^N})/;
	while (<$fh>) {
		if (/$rgx/) {
			print "$name is at ($x, $y).\n";
		}
	}
};

If what you say is true, this is the case:

Package M;
use R;
my ($name, $x, $y);
my $rgx = R->new();
 ... more code
if (/$rgx/) { }
1;

As a side, the R->new() is being used as just a class function call.
It does not bless() anything it appears since it is returning a string scalar.

Then somewhere else, you create multiple instances of M
(or just call M methods) in in a loop.

The my ($name, $x, $y) appear to be file scoped variables.
In the context I wrote, there is only one instance of ($name,$x,$y) no
matter how many instances of M you create (class scoped?).

If you had a method in M that creates many $rgx's, it would have to store
those qr// in an object based (M) blessed referent (hash or array) for them
and thereby thier references ($name,$x,$y) to persist.

Usually this involves fleshing out either R or M with references to unique
lexicals.

So that this is the case (usually):

	while (<$fh>) {
		if (/$obj->$rgx/) {
			print "$obj->$name is at ($obj->$x, $obj->$y).\n";
		}
	}

More than likely you would need accessors.

Hope this helps.
-sln



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

Date: Tue, 16 Jun 2009 14:39:53 -0700
From: sln@netherlands.com
Subject: Re: Lexical variables in (?{...}) regexp constructs
Message-Id: <sd3g355hsk2s22fq044phng9g9647vvlut@4ax.com>

On Tue, 16 Jun 2009 14:12:25 -0700, sln@netherlands.com wrote:

>On Tue, 16 Jun 2009 12:03:48 -0700 (PDT), Ala <ala.netstuff@gmail.com> wrote:
>
[snip]
>More than likely you would need accessors.
>
Here's an example of making a custom regex class. This is far removed
from what you want though.

In your case, you would create the regex in the constructor,
add unique references (to lexicals) in a qr// statement, then
assign it to the object hash ie. $self->{rgx} = qr//, then return
the instance. The references must be unique if thats what your goal is.

-sln

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

###
package RxP;
our @ISA = qw();

sub new
{
	my $self;
	my $class = shift;
	if (defined($_[0]) && ref($_[0]) eq 'RxP') {
		%{$self} = %{$_[0]};
		return bless ($self, $class);
	}
	$self  = {
	  'regex' => '',
	  'code'  => sub{''},
	  'type'  => 's',
	  'dflt_sub' => \&search
	};
	while (my ($name, $val) = splice (@_, 0, 2)) {
		next if (!defined $val);
		if ('regex' eq lc $name) {
			$self->{'regex'} = $val;
		}
		elsif ('code' eq lc $name && ref($val) eq 'CODE') {
			$self->{'code'} = $val;
		}
		elsif ('type' eq lc $name && $val =~ /(sg|gs|rg|gr|s|r)/i) {
			set_type ($self, lc $1);
		}
	}
	return bless ($self, $class);
}
sub get_type
{
	return $_[0]->{'type'};
}
sub set_type
{
	return 0 unless (defined $_[1]);
	if ($_[1] =~ /(sg|gs|rg|gr|s|r)/i) {
		$_[0]->{'dflt_sub'} = {
		   's'  => \&search,
		   'sg' => \&search_g,
		   'gs' => \&search_g,
		   'r'  => \&replace,
		   'rg' => \&replace_g,
		   'gr' => \&replace_g
		}->{lc $1};
		$_[0]->{'type'} = lc $1;
		return 1;
	}
	return 0;
}
sub clone
{
	# clone self, return new
	return RxP->new( $_[0]);
}
sub copy
{
	# copy other to self, return self
	return $_[0] unless (defined $_[1] && ref($_[1]) eq 'RxP');
	%{$_[0]} = %{$_[1]};  # no need for deep recursion
	return $_[0];
}
sub apply
{
	return 0 unless (defined $_[1]);
	return &{$_[0]->{'dflt_sub'}};
}
sub search
{
	return 0 unless (defined $_[1]);
	return $_[1] =~ /$_[0]->{'regex'}/;
}
sub search_g
{
	return 0 unless (defined $_[1]);
	return $_[1] =~ /$_[0]->{'regex'}/g;
}
sub replace
{
	return 0 unless (defined $_[1]);
	return $_[1] =~ s/$_[0]->{'regex'}/&{$_[0]->{'code'}}/e;
}
sub replace_g
{
	return 0 unless (defined $_[1]);
	return $_[1] =~ s/$_[0]->{'regex'}/&{$_[0]->{'code'}}/ge;
}



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

Date: Tue, 16 Jun 2009 16:55:59 -0700
From: sln@netherlands.com
Subject: Re: Lexical variables in (?{...}) regexp constructs
Message-Id: <q2cg355qebgejhsfssg5h4l1ja1195994o@4ax.com>

On Tue, 16 Jun 2009 14:12:25 -0700, sln@netherlands.com wrote:

>On Tue, 16 Jun 2009 12:03:48 -0700 (PDT), Ala <ala.netstuff@gmail.com> wrote:
>
>>On Jun 15, 5:00 pm, s...@netherlands.com wrote:
>>
>>> Probably the key phrase is "the Perl code contained in these blocks";
>>> Imbedding code inside of a regular expression really has limited use
>>> unless used in conjunction with a conditional or to immediatly store
>>> the value of the last capture group.
>>
>>Thanks for the reply. I realize my post wasn't very informative, and
>>that I'm probably playing with fire :)
>>Storing the last captured match is exactly what I'm using this
>>construct for. The basic idea is that I created a module to help parse
>>some non-trivial file format. The constructor of this module allows
>>the user to specify which parts of each record to capture and into
>>which variable to put it. It returns a compiled regexp that the user
>>can use when parsing. Something like this contrived example:
>>
>>  use R;
>>  my ($name, $x, $y);
>>  my $rgx = R->new(-capture => {
>>                                name => \$name,
>>                                locx => \$x,
>>                                locy => \$y,
>>                               });
>>
>>  #... later on .. use $rgx ..
>>  while (<$fh>) {
>>    if (/$rgx/) {
>>      print "$name is at ($x, $y).\n";
>>    }
>>  }
>>
>>I used this module as part of a larger module, let's call it M, that
>>parses the whole file and defines some other methods to manipulate the
>>data.
>>For the most part, this works perfectly well. Weird things start to
>>happen, seemingly in a random fashion, when I instantiate module M
>>multiple times in a loop.
>>
>>I guess I shouldn't be relying on experimental features, but since the
>>docs mentioned a work-around, I was curious.
>>
>>Thanks,
>>--Ala
>
>As far as I know, lexicals scoped within the block that initiates the
>regex, should be ok, be it a reference or not (haven't tried it but assume its ok).
>pseudo - example:
>SCOPE:
>{
>	my ($name, $x, $y);
>	my ($ref_name, $ref_x, $ref_y) = (\$name, \$x, \$y);
>
>	my $rgx = qr/([a-z,A-Z]+)(?{$$name = $^N})(\d\d)(?{$$x = $^N}),(\d\d)(?{$$y = $^N})/;
                                    $$ref_name              $$ref_x             $$ref_y

Sorry, I just mindlessly do this, depending too much on the compiler/interpreter to catch stuff.
But, thats what crafts are... fix/debug/refactor, rinse, repeat

-sln


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

Date: Tue, 16 Jun 2009 08:31:54 -0700 (PDT)
From: joe <jcharth@gmail.com>
Subject: sort array of string with tab separated items
Message-Id: <59012a9d-569e-4dac-aa28-1c6464d6f864@d7g2000prl.googlegroups.com>

Hello I have an array of a string of items separated by a tab.
Something like this
"country\tfirstname\taddress\tsomethingelse"
Is there a way to sort the array by one of these fields? or even
harder to sort by country and then by firstname?
If not Ill simply re arange the items and sort it Thanks.


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

Date: Tue, 16 Jun 2009 08:39:08 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: sort array of string with tab separated items
Message-Id: <iqef359h80h3fb5jokcbas56ncn7so9d6a@4ax.com>

joe <jcharth@gmail.com> wrote:
>Hello I have an array of a string of items separated by a tab.
>Something like this
>"country\tfirstname\taddress\tsomethingelse"
>Is there a way to sort the array by one of these fields? or even
>harder to sort by country and then by firstname?
>If not Ill simply re arange the items and sort it Thanks.

Trivial.
Use the standard sort() function, and supply your own comparison
function, which in turn split()s each argument into the four components
and compares the ones you are interested in.

While a Schwartzian Transformation may gain you some speed it's not
really necessary unless your data set is very large and you run into
actual time constraints.

jue


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

Date: Tue, 16 Jun 2009 18:58:39 +0200
From: ace <nn@nn.com>
Subject: Re: sort array of string with tab separated items
Message-Id: <h18j00$pvs$1@ss408.t-com.hr>

joe wrote:
> Hello I have an array of a string of items separated by a tab.
> Something like this
> "country\tfirstname\taddress\tsomethingelse"
> Is there a way to sort the array by one of these fields? or even
> harder to sort by country and then by firstname?
> If not Ill simply re arange the items and sort it Thanks.

my @sorted =
  map $_->{line},
  sort {
    $a->{country} cmp $b->{country}
       ||
    $a->{firstname} cmp $b->{firstname}
  }
  map {
    my %h = (line => $_);
    @h{qw/country firstname  /} = split /\t/, $_, 2;
    \%h;
  }
  @array_of_string;

For greater efficiency use array instead of %h hash.


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

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


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