[Israel.pm] What am I missing

Ephraim Dan E.Dan at F5.com
Thu Oct 15 00:49:18 PDT 2009


You have a string in a scalar which you want to use as a perl operator - you need eval for that.

I guess eval wouldn't be so bad, as long as you 100% trust (i.e. you sanitized) the input string you are eval'ing.

The only other option off the top of my head is a big if/elsif in which you handle all the cases yourself - ugly, but safe.



-----Original Message-----
From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf Of Levenglick Dov-RM07994
Sent: Thursday, October 15, 2009 09:42
To: Perl in Israel
Subject: Re: [Israel.pm] What am I missing

Why do I have to eval, and what would be the better way?

 
Best Regards,
Dov Levenglick
SmartDSP OS Development Leader

-----Original Message-----
From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf Of Ephraim Dan
Sent: Thursday, October 15, 2009 09:40
To: Perl in Israel
Subject: Re: [Israel.pm] What am I missing

You're missing string "eval" but there is probably a better way to go about it...

-----Original Message-----
From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf Of Levenglick Dov-RM07994
Sent: Thursday, October 15, 2009 09:20
To: Perl in Israel
Subject: [Israel.pm] What am I missing

Hi,
I'm trying to write an OO module which has an attribute of file operators to test against.


    opendir (my $DIR, $path) or _carp("Can't opendir $path ($!)\n");
    my @contents = readdir ($DIR);
    closedir $DIR;
    
    my @dirs = grep {-d} File::Spec->no_upwards(@contents);    
    my @bad_files = grep {$self->{"_FILE_ATTR"}} @contents;
    my @good_files = grep {-T} @contents;
    
    print "Flags: $self->{_FILE_ATTR}\n\n";
    print "Bad: @bad_files\n\n";
    print "Good: @good_files\n"; 
    
This produces:
Flags: -T

Bad: . .. AutoTest CVS cw_stationery demos doc drivers include initialization lib Release Notes.txt SmartDSP OS_release_note.doc source tests tools training

Good: Release Notes.txt


Do you know why there is a difference between the two grep operation outputs?


This is perl, v5.10.0 built for MSWin32-x86-multi-thread (with 5 registered patches, see perl -V for more detail)

Copyright 1987-2007, Larry Wall

Binary build 1003 [285500] provided by ActiveState http://www.ActiveState.com
Built May 13 2008 16:52:49




 
Best Regards,
Dov Levenglick
SmartDSP OS Development Leader,
DevTech, Technology and System Organization
Freescale Semiconductor Israel
Tel. +972-9-952-2804
The information contained in this email is classified as:
[ ] Freescale General Business Information
[x] Freescale Internal Use Only
[ ] Freescale Confidential Proprietary
[ ] Personal Memorandum
SAVE PAPER - THINK BEFORE YOU PRINT

_______________________________________________
Perl mailing list
Perl at perl.org.il
http://mail.perl.org.il/mailman/listinfo/perl
_______________________________________________
Perl mailing list
Perl at perl.org.il
http://mail.perl.org.il/mailman/listinfo/perl
_______________________________________________
Perl mailing list
Perl at perl.org.il
http://mail.perl.org.il/mailman/listinfo/perl


More information about the Perl mailing list