Re: String in Array
On Thu, 20 Feb 2014 15:05:42 -0600, Matt wrote: >my @alarm = ("xyz", "abc"); >>my $name = "ab"; >>unless (grep {/$name/} @alarm) { # do this } >If I set 'my $name = "abc";' it seems to match. But I want to match >on "ab" as well. It appears to do this already. #!/usr/bin/perl -w use 5.14.0; my @alarm = ("xyz", "abc"); my $name = "ab"; my $name1 = "abc"; # Check "ab". unless ( grep { /$name/ } @alarm ) { say "$name not found"; } else { say "$name found"; } # Check "abc". unless ( grep { /$name1/ } @alarm ) { say "$name1 not found"; } else { say "$name1 found"; } [OUTPUT] ab found abc found -- Peter Gordon, pete...@netspace.net.au on 02/21/2014 -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: String in Array
> Having trouble making this work. > > my @alarm = ("xyz", "abc"); > my $name = "ab"; > unless (grep {/$name/} @alarm) { # do this } > > Since "ab" is contained in the array I want it to NOT 'do this'. What > have I got wrong? If I set 'my $name = "abc";' it seems to match. But I want to match on "ab" as well. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Passing multiple select statements to MySQL
On Feb 19, 2014, at 4:20 AM, Dr.Ruud wrote: > my $sth_4; > ... > (untested) Thanks for the code but I still get the same error: DBD::mysql::st execute failed: You have an error in your SQL syntax; - Long pause for trial and error -- Well with the help of the author, I was able to get it to work. This is the code I used before, based on the CPAN page: use SQL::SplitStatement; my @statements = $sql_splitter->split($query_4); my $sql_string = join ' ', @statements; my $sth_4 = $dbh->prepare($sql_string); $sth_4->execute(); and this is the working code that he sent me: use SQL::SplitStatement; my @statements = $splitter->split( $query_4 ); foreach my $statement (@statements) { $sth_4 = $dbh->prepare($statement); $sth_4->execute(); } I know I had tried something similar, but it didn't work before and now it does. :\ Thanks, Frank http://www.surfshopcart.com/ Setting up shop has never been easier! -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: String in Array
On 02/20/2014 02:04 PM, Matt wrote: Having trouble making this work. my @alarm = ("xyz", "abc"); my $name = "ab"; unless (grep {/$name/} @alarm) { # do this } Since "ab" is contained in the array I want it to NOT 'do this'. What have I got wrong? can you show this not working? it looks good to me. grep will return a boolean value in scalar context. this prints nothing. same logic. perl -e '@a = qw( x y ); print "not found\n" unless grep /x/, @a' uri -- Uri Guttman - The Perl Hunter The Best Perl Jobs, The Best Perl Hackers http://PerlHunter.com -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: String in Array
On Thu, 20 Feb 2014 13:04:56 -0600, Matt wrote: >Having trouble making this work. > >my @alarm = ("xyz", "abc"); >my $name = "ab"; >unless (grep {/$name/} @alarm) { # do this } > >Since "ab" is contained in the array I want it to NOT 'do this'. >What >have I got wrong? > Use word boundaries #!/usr/bin/perl -w use 5.14.0; my @alarm = ("xyz", "abc"); my $name = "ab"; unless (grep {/\b$name\b/} @alarm) { print "Not in array!\n" } -- Peter Gordon, pete...@netspace.net.au on 02/21/2014 -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
String in Array
Having trouble making this work. my @alarm = ("xyz", "abc"); my $name = "ab"; unless (grep {/$name/} @alarm) { # do this } Since "ab" is contained in the array I want it to NOT 'do this'. What have I got wrong? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: time based test
Thanks Also, for completeness, in that doc is also stated Time::Warp and someone also pointed me to Time::Mock and Test::TimeMock. The later seems to have the best interface for my needs, so I'll go with that. On Sat, Feb 15, 2014 at 6:05 AM, David Precious wrote: > On Fri, 14 Feb 2014 16:21:52 -0500 > shawn wilson wrote: > >> What I want is to be able to make a program /think/ that it's like a >> week in the future without messing with the system time at all. So >> something that overrides gmtime and localtime and the like with some >> starting point would be awesome. Anything like that? >> > > Time::Fake on CPAN appears to fit the bill: > > https://metacpan.org/pod/Time::Fake > > Install it, then e.g.: > > perl -MTime::Fake="+20y" yourscript.pl > > (See the docs for the various options etc.) > > > -- > David Precious ("bigpresh") > http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter > www.preshweb.co.uk/linkedinwww.preshweb.co.uk/facebook > www.preshweb.co.uk/cpanwww.preshweb.co.uk/github > > > > -- > 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/