Re: file::find
oryann9 wrote: Perl'ers, I was going to reply but I see that this is also posted to PerlMonks. :( John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order.-- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Calling perl module located in some other folder.
On Jan 4, 2008 12:42 PM, Shilpi Harpavat <[EMAIL PROTECTED]> wrote: > I created a module in a file called utilities .pm in some folder say > C:\wamp\ww\perl\utilities\ which has a function say "Func1" > Now I want to use this module in a test.pl file use lib 'C:/wamp/ww/perl/utilities/'; use utilities; # loads C:\wamp\ww\perl\utilities\utilities.pm I don't have a Windows machine to try that on, but I think that should get you on the right track. The 'use lib' line tells perl where to look first for new modules. If you get an error message, that message should tell you where perl is looking (and not finding) your module; you can use that feedback to adjust the 'use lib' line accordingly. Good luck with it! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: file::find
On Jan 4, 2008 12:33 PM, oryann9 <[EMAIL PROTECTED]> wrote: > if ( $fs =~ m|\x2f{1}?|g ) { ##-- if "/" is matched --# That's a pretty hard way to write the pattern m#/#. And it's wrong, too, since you have a /g modifier on it. Or maybe I'm misunderstanding what you're doing. Did you mean to use the scalar m//g? > elsif ( $fs !~ m|\/\w+| ) { This elsif always fires, doesn't it? I can't see how you're thinking that this pattern could match if the first didn't find a forward slash. Is there something else going on here? Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Calling perl module located in some other folder.
hi, I created a module in a file called utilities .pm in some folder say C:\wamp\ww\perl\utilities\ which has a function say "Func1" Now I want to use this module in a test.pl file If I use use utilities; or use "C:\wamp\www\perl\utilities"; it doesnt work How can i access the module functions ?? Thanks Shilpi -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
file::find
Perl'ers, In my code I call a find routine called xyz based on what the user enters which can be "/" or /\w+. Instead of having one block of code and another block of the same code, but with $File::Find::prune = 1; can't I just pass this $File::Find::prune = 1; to my single find routine based on their entry? use strict; use warnings; use File::Find ; use File::Find::Closures qw(find_by_min_size) ; chomp (my $fs = <>) ; if ( $fs =~ m|\x2f{1}?|g ) { ##-- if "/" is matched --# $File::Find::prune = 1; find_me; } elsif ( $fs !~ m|\/\w+| ) { find_me; find_me { my @directory = ($fs) ; use constant MAX_SIZE => (25*1024*1024) ; use constant DIVISOR => (1024) ; my ( $wanted, $list ) = find_by_min_size ( MAX_SIZE ) ; File::Find::find ( { wanted => $wanted, }, @directory ) ; } thank you Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Odd DBM::Deep behavior "cannot store tied value" using literal key name
On Jan 4, 2008 11:18 AM, Roman Daszczyszak <[EMAIL PROTECTED]> wrote: > I'm using ActiveState Perl 5.8.8 820, with DBM:Deep 0.983 on Windows > XP w/SP2 and all latest hotfixes installed. > > The problem I'm having seems to be related to the \%testhash element > at the end of @old and @same. If I change that to it's own hash, the > problem disappears. snip When I downgrade to 0.983 I immediately get "DBM::Deep: File type mismatch" even with your original code. I would suggest upgrading DBM::Deep to version 1.0006. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Odd DBM::Deep behavior "cannot store tied value" using literal key name
I'm using ActiveState Perl 5.8.8 820, with DBM:Deep 0.983 on Windows XP w/SP2 and all latest hotfixes installed. The problem I'm having seems to be related to the \%testhash element at the end of @old and @same. If I change that to it's own hash, the problem disappears. On Jan 4, 2008 5:03 PM, Chas. Owens <[EMAIL PROTECTED]> wrote: > On Jan 4, 2008 9:13 AM, Roman Daszczyszak <[EMAIL PROTECTED]> wrote: > snip > > The above code works as-is, but if I uncomment the line(s) above > > (marked with a comment), I get the error: DBM::Deep: Cannot store a > > tied value. > > > > Why is that? > snip > > Hmm, it seems to work for me. The output of the following code is > > 144.1 => [ 00-99-48-AF-46-43, W117, 1, 1197390385, { alice => 20, bob > => 23, }, ] > 145.2 => [ 00-99-48-AF-46-43, W117, 1, 1197390385, { alice => 20, bob > => 23, }, ] > 146.3 => [ 00-99-48-AF-46-43, W117, 1, 1197390385, { alice => 24, bob > => 23, }, ] > > Which seems to be right and I am not getting any errors or warnings. > What version DBM::Deep are you using (I just installed from CPAN)? > What version of Perl are you using (5.8.4 for me). Which OS are you > on (OS X 10.4 for me)? > > #!/perl/bin/perl > use strict; > use warnings; > > #use Data::Compare; > use DBM::Deep; > > my $database = &OpenDB("test.db"); > > my %testhash = ( 'bob' => 23, 'alice' => 20 ); > my @old = ("00-99-48-AF-46-43", "W117", 1, 1197390385, \%testhash); > my @same = ("00-99-48-AF-46-43", "W117", 1, 1197390385, \%testhash); > > my %newhash = ( 'bob' => 23, 'alice' => 24 ); > my @new = ("00-99-48-AF-46-43", "W117", 1, 1197390385, \%newhash); > > my $ip1 = "144.1"; > my $ip2 = "145.2"; > my $ip3 = "146.3"; > > $database->{$ip1} = [EMAIL PROTECTED]; > # Uncomment the line directly below to generate error > $database->{$ip2} = [EMAIL PROTECTED]; > $database->{$ip3} = [EMAIL PROTECTED]; > > my @test_old = @{$database->{$ip1}}; > my @test_same = @{$database->{$ip2}}; > my @test_new = @{$database->{$ip3}}; > > for my $key (sort keys %$database) { > print "$key => [ "; > for my $elt (@{$database->{$key}}) { > if (ref $elt) { > print "{ "; > print map { "$_ => $elt->{$_}, " } sort keys %$elt; > print "}, "; > } else { > print "$elt, "; > } > } > print "]\n"; > > } > > sub OpenDB > { ># Argument(s): A string containing the database filename to be used. ># Returned: A scalar reference holding the database object. ># Globals: None. >my ($filename) = @_; >my $db = DBM::Deep->new( >file => $filename, >locking => 1, >autoflush => 1 );# Test: see if removing this increases speed >return($db); > } > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Odd DBM::Deep behavior "cannot store tied value" using literal key name
On Jan 4, 2008 9:13 AM, Roman Daszczyszak <[EMAIL PROTECTED]> wrote: snip > The above code works as-is, but if I uncomment the line(s) above > (marked with a comment), I get the error: DBM::Deep: Cannot store a > tied value. > > Why is that? snip Hmm, it seems to work for me. The output of the following code is 144.1 => [ 00-99-48-AF-46-43, W117, 1, 1197390385, { alice => 20, bob => 23, }, ] 145.2 => [ 00-99-48-AF-46-43, W117, 1, 1197390385, { alice => 20, bob => 23, }, ] 146.3 => [ 00-99-48-AF-46-43, W117, 1, 1197390385, { alice => 24, bob => 23, }, ] Which seems to be right and I am not getting any errors or warnings. What version DBM::Deep are you using (I just installed from CPAN)? What version of Perl are you using (5.8.4 for me). Which OS are you on (OS X 10.4 for me)? #!/perl/bin/perl use strict; use warnings; #use Data::Compare; use DBM::Deep; my $database = &OpenDB("test.db"); my %testhash = ( 'bob' => 23, 'alice' => 20 ); my @old = ("00-99-48-AF-46-43", "W117", 1, 1197390385, \%testhash); my @same = ("00-99-48-AF-46-43", "W117", 1, 1197390385, \%testhash); my %newhash = ( 'bob' => 23, 'alice' => 24 ); my @new = ("00-99-48-AF-46-43", "W117", 1, 1197390385, \%newhash); my $ip1 = "144.1"; my $ip2 = "145.2"; my $ip3 = "146.3"; $database->{$ip1} = [EMAIL PROTECTED]; # Uncomment the line directly below to generate error $database->{$ip2} = [EMAIL PROTECTED]; $database->{$ip3} = [EMAIL PROTECTED]; my @test_old = @{$database->{$ip1}}; my @test_same = @{$database->{$ip2}}; my @test_new = @{$database->{$ip3}}; for my $key (sort keys %$database) { print "$key => [ "; for my $elt (@{$database->{$key}}) { if (ref $elt) { print "{ "; print map { "$_ => $elt->{$_}, " } sort keys %$elt; print "}, "; } else { print "$elt, "; } } print "]\n"; } sub OpenDB { # Argument(s): A string containing the database filename to be used. # Returned: A scalar reference holding the database object. # Globals: None. my ($filename) = @_; my $db = DBM::Deep->new( file => $filename, locking => 1, autoflush => 1 );# Test: see if removing this increases speed return($db); } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Odd DBM::Deep behavior "cannot store tied value" using literal key name
Hi all, I am trying to create a test script for some work I'm trying to do with Data::Compare using DBM::Deep, but the test code is acting flaky and I'm not sure why. In a previous (and working) script, I have a DBM::Deep hash keyed using IP addresses. Inside the hash is an array that contains several values including an array reference and a hash reference. This works fine. The test script is a different story. Here's the code: --- #!/perl/bin/perl use strict; use warnings; use Data::Compare; use DBM::Deep; my $database = &OpenDB("test.db"); my %testhash = ( 'bob' => 23, 'alice' => 20 ); my @old = ("00-99-48-AF-46-43", "W117", 1, 1197390385, \%testhash); my @same = ("00-99-48-AF-46-43", "W117", 1, 1197390385, \%testhash); my %newhash = ( 'bob' => 23, 'alice' => 24 ); my @new = ("00-99-48-AF-46-43", "W117", 1, 1197390385, \%newhash); my $ip1 = "144.1"; my $ip2 = "145.2"; my $ip3 = "146.3"; $database->{$ip1} = [EMAIL PROTECTED]; # Uncomment the line directly below to generate error # $database->{$ip2} = [EMAIL PROTECTED]; # $database->{$ip3} = [EMAIL PROTECTED]; my @test_old = @{$database->{$ip1}}; # my @test_same = @{$database->{$ip2}}; # my @test_new = @{$database->{$ip3}}; sub OpenDB { # Argument(s): A string containing the database filename to be used. # Returned: A scalar reference holding the database object. # Globals: None. my ($filename) = @_; my $db = DBM::Deep->new( file => $filename, locking => 1, autoflush => 1 );# Test: see if removing this increases speed return($db); } --- The above code works as-is, but if I uncomment the line(s) above (marked with a comment), I get the error: DBM::Deep: Cannot store a tied value. Why is that? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: removing duplicate lines across files.
Hi Gurus, Sorry I did not give detailed description of the problem, Here it goes I have a array of file names (file1, file2, file3, file4). Each the duplicates should be removed in the below fashion The lines in file1 should be removed from file2,fiile3,file4,If they exists. The lines in file2 should be removed from file3,file4 if They exists, The lines in file3 should be removed from file4 if they exists. Is there any way apart from forloop Thanks in Advance Siva -Original Message- From: John W. Krahn [mailto:[EMAIL PROTECTED] Sent: Thursday, January 03, 2008 4:04 PM To: Perl Beginners Subject: Re: removing duplicate lines across files. Siva Prasad wrote: > > Hi Gurus, Hello, > I want to remove duplicate lines across files. > > Below is the detailed problem, > > > I have file1 file2,file3,file4,file5, > > The lines in file1 are there in file2,file3,file4,file5 I want to remove > all the lines which are there in file1 from file2,file3,file4,file5. > > Can anybody please tell me to solve the above problem? UNTESTED: #!/usr/bin/perl use warnings; use strict; my $file = 'file1'; open my $fh, '<', $file or die "Cannot open '$file' $!"; my %lines; @lines{ <$fh> } = (); close $fh; { local ( $^I, @ARGV ) = qw/ .bak file2 file3 file4 file5 /; while ( <> ) { next if exists $lines{ $_ }; print; } } __END__ John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order.-- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: How to extract the HTML tag?
On 1月4日, 上午2時45分, [EMAIL PROTECTED] (Chas. Owens) wrote: > You could try saying > > $str =~ /<\s*(\w+).*?>/gm > Thanks, this is good enough for me. Howard -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: How to make "a(b" as "a\(b"?
On Jan 3, 6:32 am, [EMAIL PROTECTED] (Chas. Owens) wrote: > On Jan 2, 2008 11:11 PM, Murali <[EMAIL PROTECTED]> wrote:> Hi, > > > I have a scalar variable $x whose value is "a(b" > > > I am trying to replace the paranthesis with a backslash followed by > > parenthesis, I mean, ( to \( > > > $x =~ s/\(/\\(/g; > > > However this is making $x as "a\\(b" which is not what I want. > > snip > > One of those two statements is false. If $x holds only "a(b" then $x > =~ s/\(/\\(/g will result in $x holding "a\(b" > > perl -le '$x = "a(b"; print $x; $x =~ s/\(/\\(/; print $x' > > prints > > a(b > a\(b > > So, if you are seeing 'a\\(b' then one of two things is occurring: > 1. you aren't really seeing 'a\\(b', you just think it is there > because that is what is in the replacement string > 2. $x doesn't just contain "a(b" > > I would suggest printing the variable to the screen to see if it > really contains 'a\\(b'. If it doesn't (and I expect that it > doesn't), I would suggest going back and rereading the Quote and > Quote-like Operators section in perldoc perlop > orhttp://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operatorsto > understand why a \\ in the second part of the substitutionis turning > into a \ in the output (hint: it has to do with interpolation and > escapes). > > If you do indeed see a second backslash in the output then $x must not > have contained what you said it contained. Go back an take a better > look at it. If it contains something like 'a(b a\(b' then the > substitution will turn it into 'a\(b a\\(b'. You can use the > zero-width negative look-behind assertion* that John mentions in his > email to prevent it from prepending a \ to a ( that is already > preceded by a \. > > * read more in perldoc perlre > orhttp://perldoc.perl.org/perlre.html#Look-Around-Assertions Thanks to all those who responded. I was testing the above snippet in perl's debugger mode and was using x to print the variable and hence it was showing two backslashes. When I tried print, it worked just fine. -Murali -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/