Re: perl equivelent of which in bash

2012-01-04 Thread Jim Green
Thank you! I should have searched cpan.

Jim.


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




perl equivelent of which in bash

2012-01-04 Thread Jim Green
Greetings!
basically I need a perl equivalent in bash that does which and gives me the 
binary path. I need this because I run my script in different systems I want 
the binary automatically adjusted.

Thanks!
Jim.


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: perl memory issue

2011-07-25 Thread Jim Green

pls ignore this post, it has nothing to do with perl itself. the
sender is basically overwhelming the receiver que and receiver
couldn't handle fast enough..

Thanks.


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




perl memory issue

2011-07-24 Thread Jim Green
Hello!

I have the following code which is giving me trouble, basically I was
tesing the Tibco::Rv module this was just a test program. what it does
is it creates a listener and calls a simple callback when the listener
sees a message. I ran this script but the memory use gets larger and
larger as time passes by. I understand as the callback is called more
and more times, perl reclaims the memory but never gives it back to
the
OS. So how could I modify the following code so that it runs without
consuming more memory?

Thanks!
Jim



my ($service,$network,$daemon) = qw(1 ;238.238.238.238 7500);
my ( $rv ) = Tibco::Rv->new(
service => $service,
network => $network,
daemon => $daemon
);

my ($listener) = $rv->createListener(
subject => '>',
callback => \&process_msg,
);
$rv->start;


sub process_msg {
my  ( $msg )= @_;
my $content = $msg->getFieldByIndex(0);
my $data = $content->{'data'};
print "$msg\n";
print $data,"\n";
return ;
}   # --  end of subroutine process_msg  --




-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: edit_file and edit_file_lines

2011-06-07 Thread Jim Green
On May 15, 1:28 am, u...@stemsystems.com ("Uri Guttman") wrote:
> hi all,
>
> As with other releases of File::Slurp I think this list should be told
> about it since this module is so easy to use and makes your Perl much
> simpler and also faster.
>
> uri
>
> Have you ever wanted to use perl -pi inside perl? did you have the guts
> to localize $^I and @ARGV to do that? now you can do that with a simple
> call toedit_fileor edit_file_lines in the new .018 release of
> File::Slurp. Now you can modify a file in place with a simple call.
>
> edit_filereads a whole file into $_, calls its code block argument and
> writes $_ back out the file. These groups are equivalent operations:
>
>         perl -0777 -pi -e 's/foo/bar/g' filename
>
>         use File::Slurp qw(edit_file) ;
>
>        edit_file{ s/foo/bar/g } 'filename' ;
>
>        edit_filesub { s/foo/bar/g }, 'filename' ;
>
>        edit_file\&replace_foo, 'filename' ;
>         sub replace_foo { s/foo/bar/g }
>
> edit_file_lines reads a whole file and puts each line into $_, calls its
> code block argument and writes each $_ back out the file. These groups are
> equivalent operations:
>
>         perl -pi -e '$_ = "" if /foo/' filename
>
>         use File::Slurp qw( edit_file_lines ) ;
>
>         edit_file_lines { $_ = '' if /foo/ } 'filename' ;
>
>         edit_file_lines sub { $_ = '' if /foo/ }, 'filename' ;
>
>        edit_file\&delete_foo, 'filename' ;
>         sub delete_foo { $_ = '' if /foo/ }
>
> So now when someone asks for a simple way to modify a file from inside
> Perl, you have an easy answer to give them.

I tried my @texts = read_file( 'zcat filename.gz|' )  but it doesn't
work, could someone help with this syntax? I would use PerlIO::gz for
large files but prefer a simple call to get the content I want for
smaller files.

Thanks!
Jim.
>
> --
> Uri Guttman  --  u...@stemsystems.com    http://www.sysarch.com--
> -  Perl Code Review , Architecture, Development, Training, Support --
> -  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com-


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: edit_file and edit_file_lines

2011-06-02 Thread Jim Green
On May 15, 7:13 pm, u...@stemsystems.com ("Uri Guttman") wrote:
> >>>>> "PJ" == Paul Johnson  writes:
>
>   PJ> On Sun, May 15, 2011 at 01:31:47PM -0400, Jim Green wrote:
>   >> this is very nice, don't need to call perl in perl anymore..
>   >>
>   >> perl -pi -e '$_ = "" if /foo/' filename
>   >>
>   >> but what if the file is very large? slurping the file in to memory will
>   >> be ok?
>   >>
>   >> or is there any other alternatives you are aware of? or you can dismiss?
>
>   PJ> {
>   PJ>     local ($^I, @ARGV) = ("", "filename");
>   PJ>     while (<>)
>   PJ>     {
>   PJ>         print unless /foo/;
>   PJ>     }
>   PJ> }
>
>   PJ> is the idiomatic way to do that.  Well, to do:
>
> and also very slow and also clunky. as i said, you need to localize
> those vars and also not be using <> elsewhere. it is just a bad idiom
> and now it can be laid to rest. :)
>
>   PJ>   perl -ni -e 'print unless /foo/' filename
>
> about the same as my version. i wanted to show how you would do the same
> logic with both -pi and edit_file_lines. my sub doesn't have a print
> command so you can invert the logic which is why i used -p and not -n.
>
>   PJ> which is the idiomatic way to do what you had written.  For a more
>   PJ> direct translation, substitute the loop contents with
>
>   PJ>         $_ = "" if /foo/;
>   PJ>         print;
>
> and you don't need the print if you use -p.

Is there a preferred way to append a text file to the end of gzipped
file? the api of File::Slurp append_file is nice, but doesn't work
with gzip file...

Thanks!

>
> uri
>
> --
> Uri Guttman  --  u...@stemsystems.com    http://www.sysarch.com--
> -  Perl Code Review , Architecture, Development, Training, Support --
> -  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com-


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: memory doesn't free after lexical block

2011-05-18 Thread Jim Green
On 18 May 2011 20:39, Shawn H Corey  wrote:
> On 11-05-18 08:36 PM, Jim Green wrote:
>>
>> is this the same for other language like c++ or java?
>
> For all processes.  That's why deamons periodically respawn; to clean up
> messes like this.

Thank you! I just wish this is not a deficiency in Perl language itself.
If it is the same for other language, I am happy!

Jim

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: memory doesn't free after lexical block

2011-05-18 Thread Jim Green
On 18 May 2011 20:30, Paul Johnson  wrote:
> On Wed, May 18, 2011 at 05:16:23PM -0700, Jim Green wrote:
>> Hello List!
>> I have a quick question about memory release in perl:
>>
>> {
>>     my @array;
>>
>>     foreach my $n (1..1e7 ) {
>>         push @array, $n;
>>         print "$n\n";
>>     }
>> }
>>
>> print "sleeping\n";
>> sleep 600;
>>
>> after the code block, I epxect memory usage to drop to almost zero
>> because @array went out of scope. but when I do top after it executes
>> after the code block it still has huge memory usage..
>>
>> Could anyone give me some explanation?
>
> In general perl won't release memory back to the system, but will keep
> it around to be (possibly) reused later.  If you subsequently create
> another similarly sized array you should notice that memory use remains
> roughly the same.

lets say I have a really big perl program, if I let the it run, the
memory usage will always increase until it exits?

is this the same for other language like c++ or java?

Thank you all!
Jim

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




memory doesn't free after lexical block

2011-05-18 Thread Jim Green
Hello List!
I have a quick question about memory release in perl:

{
my @array;

foreach my $n (1..1e7 ) {
push @array, $n;
print "$n\n";
}
}

print "sleeping\n";
sleep 600;

after the code block, I epxect memory usage to drop to almost zero
because @array went out of scope. but when I do top after it executes
after the code block it still has huge memory usage..

Could anyone give me some explanation?

Thanks!
Jim


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: edit_file and edit_file_lines

2011-05-15 Thread Jim Green
On 15 May 2011 01:28, Uri Guttman  wrote:
>
> hi all,
>
> As with other releases of File::Slurp I think this list should be told
> about it since this module is so easy to use and makes your Perl much
> simpler and also faster.
>
> uri
>
> Have you ever wanted to use perl -pi inside perl? did you have the guts
> to localize $^I and @ARGV to do that? now you can do that with a simple
> call to edit_file or edit_file_lines in the new .018 release of
> File::Slurp. Now you can modify a file in place with a simple call.
>
> edit_file reads a whole file into $_, calls its code block argument and
> writes $_ back out the file. These groups are equivalent operations:
>
>        perl -0777 -pi -e 's/foo/bar/g' filename
>
>        use File::Slurp qw( edit_file ) ;
>
>        edit_file { s/foo/bar/g } 'filename' ;
>
>        edit_file sub { s/foo/bar/g }, 'filename' ;
>
>        edit_file \&replace_foo, 'filename' ;
>        sub replace_foo { s/foo/bar/g }
>
> edit_file_lines reads a whole file and puts each line into $_, calls its
> code block argument and writes each $_ back out the file. These groups are
> equivalent operations:
>
>        perl -pi -e '$_ = "" if /foo/' filename
>
>        use File::Slurp qw( edit_file_lines ) ;
>
>        edit_file_lines { $_ = '' if /foo/ } 'filename' ;
>
>        edit_file_lines sub { $_ = '' if /foo/ }, 'filename' ;
>
>        edit_file \&delete_foo, 'filename' ;
>        sub delete_foo { $_ = '' if /foo/ }
>
> So now when someone asks for a simple way to modify a file from inside
> Perl, you have an easy answer to give them.

this is very nice, don't need to call perl in perl anymore..

 perl -pi -e '$_ = "" if /foo/' filename

but what if the file is very large? slurping the file in to memory will
be ok?

or is there any other alternatives you are aware of? or you can dismiss?

Thanks!

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: yaml file conversion

2011-03-04 Thread Jim Green
Thanks Brandon, YAML should get some functions to manipulate it..

On Thu, Mar 3, 2011 at 7:56 PM, Brandon McCaig  wrote:
> On Thu, Mar 3, 2011 at 6:39 PM, Brandon McCaig  wrote:
>> I don't know if I'd call it easier. I'm not personally familiar with
>> YAML so I only bothered to parse the example that you gave.
>
> Actually looking into YAML it seems much more complicated than this so
> unless you know for sure that the input complexity is simple (and have
> a good technical reason to manually parse it), I would encourage you
> to use a module instead. That said, it seems non-trivial to determine
> how to invert the keys on an undetermined data structure, so it might
> be too much to ask to write this program with an arbitrary YAML
> structure without defining the exact requirements (and justification).
>
> (As a side note, I erroneously removed indentation from the source
> data in my sample program when I pasted it into Vim, but the program
> will work even with the indentation)
>
>
> --
> Brandon McCaig  
> V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
> Castopulence Software  
> 
>

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: yaml file conversion

2011-03-04 Thread Jim Green
On Thu, Mar 3, 2011 at 6:31 PM, Jim Gibson  wrote:
> On 3/3/11 Thu  Mar 3, 2011  3:11 PM, "Jim Green"
>  scribbled:
>
>> On Mar 3, 5:44 pm, shawnhco...@gmail.com (Shawn H Corey) wrote:
>>> On 11-03-03 05:40 PM, Jim Green wrote:
>>>
>>>> But is there a easier way of
>>>> doing this I might not be aware of?
>>>
>>> Given your brief description, no.  The problem is that you can't output
>>> the first datum without reading the last, because the last may be the
>>> first thing that needs to be outputted.
>>
>> Hello, let me generalize this problem,
>> lets say I have a hash with 2 levels of keys,
>> I want to convert this hash to another hash but with the 2 levels of
>> keys reversed.. I hope there is a module or sth that can do it.
>
> That is a simple problem that doesn't need a module (although one may
> exist).
>
> Untested:
>
> my %oldhash = ( a => { b=>c, d=>e }, f => {g=>h, i=>j}, ... );
> my %newhash;
> for( my($key1,$val1) = each %oldhash ) {
>  for( my($key2,$val2) = each %{$val1} ) {
>    $newhash{$key2}->{$key1} = $val2;
>  }
> }

Thanks Jim, this will definitely work. but changing order of keys is a
general problems and hopefull some module exists to do that.

Jim

>
>
>

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: yaml file conversion

2011-03-03 Thread Jim Green
On Mar 3, 5:44 pm, shawnhco...@gmail.com (Shawn H Corey) wrote:
> On 11-03-03 05:40 PM, Jim Green wrote:
>
> > But is there a easier way of
> > doing this I might not be aware of?
>
> Given your brief description, no.  The problem is that you can't output
> the first datum without reading the last, because the last may be the
> first thing that needs to be outputted.

Hello, let me generalize this problem,
lets say I have a hash with 2 levels of keys,
I want to convert this hash to another hash but with the 2 levels of
keys reversed.. I hope there is a module or sth that can do it.

Hope this makes the problem clearer.

Thanks!
Jim

>
> --
> Just my 0.0002 million dollars worth,
>    Shawn
>
> Confusion is the first step of understanding.
>
> Programming is as much about organization and communication
> as it is about coding.
>
> The secret to great software:  Fail early & often.
>
> Eliminate software piracy:  use only FLOSS.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




yaml file conversion

2011-03-03 Thread Jim Green
Hello:
I have a yaml file

key1:
  a: value1
  b: value1
key2:
  a: value2
  b: value2

I want it converted to

a:
key1:value1
key2:value2
b:
key1:value1
key2:value2

I could use YAML module to load the first yaml file to a hash and
manually populate another hash and dump. But is there a easier way of
doing this I might not be aware of?

Thanks!
Jim


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/





encapsulate static data

2011-02-09 Thread Jim Green
Hello:
I have some static data I want to wrap in a Data.pm, what is the best
way of doing this.

package data;
use strict;
use warnings;

my $data=1;
1;

I tried
use data;
print $data; but it doesn't work, also I tried print data::$data and
still doesn't work.

Thanks for helping!
Jim


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




config file modules confusion

2011-02-07 Thread Jim Green
Hello
I searched cpan and was overwhelmed by the number of modules
available.

I want a config module that can do updates well, preserving formats of
original file, preserving blank lines, comments, etc. which one should
I use..?

Config::General, Config::Simple, Config::Inifiles, just to name a
few..

Thanks!
Jim


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




cgi or new stuff?

2011-02-04 Thread Jim Green
Hello,
I wrote simple cgi scripts before but want to go further, I want to
learn a little bit systematic web programming, I found catalyst and
ORMs, do you guys think with those I don't need to learn javascript,
ajax etc?

Thanks!
Jim


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




manipulating configuration files package, object oriented? moose?

2011-02-03 Thread Jim Green
Hello:

I am confronted with a task of creating a package to manipulate a set
of configuration files.

for example I need to setup up a server and need to change lots of
configuration files and create necessary sections, change values in
the file etc. Also sometimes I modify the server set up and need to
change something(values, sections etc) in the group of configuration
files.

my first thought is to write a perl module that each method use open
to open those files and use regex to manipulate those files. those
files are homemade, not standard format like xml or yaml.. but i kind
of not like it... because it is too raw.

I am learning object oriented programming and want to try out object
oriented perl on this module. this is a good exercise.  I looked at
moose, could anyone some advice on how to design the api of the module
how to make it object oriented? even use moose?

Thank you very much!!

Jim


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: parse arguments passed to subroutines

2011-01-30 Thread Jim Green
this will work, Thank you!

On 30 January 2011 22:00,   wrote:
> Jim Green writes:
>>
>> Hello,
>> I usually use my ($arg1, $arg2) = @_;
>> to get the arguments parsed to a subroutine.
>> I want this to be smarter. Sometimes I want to pass $start, $end to
>> the sub, sometimes I want to pass $start, $count to the sub.
>> but in this case my ($arg1, $arg2) = @_;  will get confused, it
>> doesn't know if the argument is meant to be $end or to be $count.
>> does subroutine have some  mechanism like getopt::long and it can know
>> what kind of arguments are passed in?
>
> Jim,
> You could pass a hash reference instead.
> %arg = (start=>'..',end=>'..',count=>'..');
> the_func(\%arg);
> Regards.
>

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




parse arguments passed to subroutines

2011-01-30 Thread Jim Green
Hello,
I usually use my ($arg1, $arg2) = @_;
to get the arguments parsed to a subroutine.

I want this to be smarter. Sometimes I want to pass $start, $end to
the sub, sometimes I want to pass $start, $count to the sub.

but in this case my ($arg1, $arg2) = @_;  will get confused, it
doesn't know if the argument is meant to be $end or to be $count.

does subroutine have some  mechanism like getopt::long and it can know
what kind of arguments are passed in?

Thank you in advance for pointers,
Jim


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




perl dbi question

2010-11-24 Thread Jim Green
Hello Perl community,
here is a question I encountered dbi and till now I use brute force to
solve it, but I figured I may see better way to do it here.

in orable sqlplus If I do
select * from table, it will print out the results nicely, all
aligned.

in dbi what I do now

my $body = sprintf("market_symbol   last info_volume best_bid
best_bid_size best_ask best_ask_size info_open info_low  info_high
\n");
while ($hash_ref = $sth->fetchrow_hashref) {
$body = $body.sprintf("%13s", $hash_ref->{'MARKET_SYMBOL'});
$body = $body.sprintf("%7s", $hash_ref->{'LAST'});
$body = $body.sprintf("%12s", $hash_ref->{'INFO_VOLUME'});
$body = $body.sprintf("%9s", $hash_ref->{'BEST_BID'});
$body = $body.sprintf("%13s", $hash_ref->{'BEST_BID_SIZE'});
$body = $body.sprintf("%10s", $hash_ref->{'BEST_ASK'});
$body = $body.sprintf("%14s", $hash_ref->{'BEST_ASK_SIZE'});
$body = $body.sprintf("%10s", $hash_ref->{'INFO_OPEN'});
$body = $body.sprintf("%9s", $hash_ref->{'INFO_LOW'});
$body = $body.sprintf("%10s", $hash_ref->{'INFO_HIGH'});
$body = $body.sprintf("\n");
}

I have to figure out the column width by counting them one by one, is
there some way to use dbi and print out results nicely without doing
so?

Thank you and have a nice Thx givin!

Jim


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




file::fild with awk?

2010-08-08 Thread Jim Green
Hi, 
I used to use find, a for loop and awk to extract data from a list of
files returned by find. 

Now I want to use file::find  and perl to this.

 use vars qw/*name *dir *prune/;
 *name   = *File::Find::name;
 *dir= *File::Find::dir;
 *prune  = *File::Find::prune;
 
 my $directories_to_seach="/home/jim";
  
  
  sub wanted;
  
  # Traverse desired filesystems
  File::Find::find({wanted => \&wanted}, $directories_to_seach);
  exit;
  
  sub wanted {
  /regex/s
 && print("$name\n");
  }

my question is how to do in a native, elegant perl way for my bash
script?

for file in `find . -name "*pattern*"`
do 
zcat $file|awk '$2 == "BP" {print $17 $18}'|\
echo 
done


Thank you!

Jim

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




hash reference question

2010-01-21 Thread Jim Green
i have a question for the following perl code,  by changing the value
in %h3, the script also changes the value for %h4, I vaguely
understand it is because %h3's key is reference to %h2, %h2's key is
reference to %h1,

so by changing value in %h3, the script also changes the value for %h4,
I was wondering if there is a way to address this problem, I don't
want by changing $h3{k3}{k2}{k1} = "v2", %h4 also got changed.

Thank you list for any pointers, I am absolute newbie and I am learning..   

my %h1 = ( k1 => "v1"  );   
my %h2 = ( k2 => \%h1  );   
my %h3 = ( k3 => \%h2  );   

my %h4 = %h3;   

print "h3\n";   
foreach my $i ( keys %h3 ) {
 print "$i => $h3{$i}\n";
 foreach my $j (keys %{$h3{$i}}) {
  print "  $j => $h3{$i}{$j}\n";
  foreach my $k ( keys %{$h3{$i}{$j}}) {
print "$k => $h3{$i}{$j}{$k}\n";
  }
 }
}   

$h3{k3}{k2}{k1} = "v2"; 

print "h4\n";
foreach my $i ( keys %h4 ) {
 print "$i => $h4{$i}\n";
 foreach my $j (keys %{$h4{$i}}) {
  print "  $j => $h4{$i}{$j}\n";
  foreach my $k ( keys %{$h4{$i}{$j}}) {
print "$k => $h4{$i}{$j}{$k}\n";
  }
 }
}

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: basename question from "learning perl"

2010-01-19 Thread Jim Green
Thank you all! I figured it out!

Jim
2010/1/18 Alexander Koenig :
> Hi Jim,
>
> Jim Green wrote on 01/17/2010 05:25 PM:
>> my $name = "/usr/local/bin/perl";
>> (my $basename = $name) =~ s#.*/##; # Oops!
>>
>> after substitution $basename is supposed to be
>> perl
>>
>> but why it is not /local/bin/perl? will .*/ matches longest possible string?
>
> Yes it will match the longest possible string.
> To understand how this works (and how to avoid this behaviour if you
> don't want it) look into the concept of "greedy" regular expressions.
> For example here http://perldoc.perl.org/perlretut.html
>
> bye
> Alex
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: basename question from "learning perl"

2010-01-18 Thread Jim Green
Thank you all! I figured it out!

JIm

2010/1/18 Alexander Koenig :
> Hi Jim,
>
> Jim Green wrote on 01/17/2010 05:25 PM:
>> my $name = "/usr/local/bin/perl";
>> (my $basename = $name) =~ s#.*/##; # Oops!
>>
>> after substitution $basename is supposed to be
>> perl
>>
>> but why it is not /local/bin/perl? will .*/ matches longest possible string?
>
> Yes it will match the longest possible string.
> To understand how this works (and how to avoid this behaviour if you
> don't want it) look into the concept of "greedy" regular expressions.
> For example here http://perldoc.perl.org/perlretut.html
>
> bye
> Alex
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




basename question from "learning perl"

2010-01-17 Thread Jim Green
my $name = "/usr/local/bin/perl";
(my $basename = $name) =~ s#.*/##; # Oops!

after substitution $basename is supposed to be
perl

but why it is not /local/bin/perl? will .*/ matches longest possible string?

Thank you list!

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




regex question

2009-12-22 Thread Jim Green
Hi,

I have a text file with lines like this


· Experience in C/C++ realtime system programming

· Experience in ACE, FIX


Could anybody tell me which regex to use to get rid of the dot and the
leading spaces before each Line?

Thanks for any help!

Jim



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: regex question

2009-12-21 Thread Jim Green
2009/12/22 Jim Gibson :
> s/^\.\s*//;

Thanks Jim, I will figure out as I read "learning perl".
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: regex question

2009-12-21 Thread Jim Green
2009/12/21 Uri Guttman :
>>>>>> "JG" == Jim Green  writes:
>
>  JG> I have a text file with lines like this
>
>
>  JG> ·         Experience in C/C++ realtime system programming
>
>  JG> ·         Experience in ACE, FIX
>
>
>  JG> Could anybody tell me which regex to use to get rid of the dot and the
>  JG> leading spaces before each Line?
>
> what have you tried? do you have any code at all to show? this list
> isn't for coding for you but to help perl beginners. this is a fairly
> easy problem so why don't you do a basic s/// op on a line, anchor it to
> the beginning and try to match what you don't want and replace it with
> a null string. i wrote it in english so you have to translate that to
> perl.

I am reading "learning perl" but have not proceeded to regex chapters.
I googled and got to know hot to delete preceding white space. but now
the problem is that there is an odd dot at the beginning...
I don't know how to write the pattern in s/pattern//, so a regex for
that will do. Sorry if it sounds stupid, anyway, Thanks for the help!

Jim

>
> uri
>
> --
> Uri Guttman  --  ...@stemsystems.com    http://www.sysarch.com --
> -  Perl Code Review , Architecture, Development, Training, Support --
> -  Gourmet Hot Cocoa Mix    http://bestfriendscocoa.com -
>

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




regex question

2009-12-21 Thread Jim Green
Hi,

I have a text file with lines like this


· Experience in C/C++ realtime system programming

· Experience in ACE, FIX


Could anybody tell me which regex to use to get rid of the dot and the
leading spaces before each Line?

Thanks for any help!

Jim

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/