Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

cannot open files with while (<>)

Help
kac
2010-03-06
2013-05-20
  • kac
    kac
    2010-03-06

    Hi
    I'm running Ubuntu 9.10, Eclipse 3.5.1.
    I'm learning perl and I want to use eclipse as I worked as a java programmer for a few years and thats the IDE I know.

    If I run this simple program from the command line it works fine, but if I run it from within Eclipse I get

    Can't open *.pl: No such file or directory at /home/kieran/workspace/perldev/perl-grep.pl line 10.
    Current directory is /home/kieran/workspace/perldev
    Regex is

    my run config has perl-grep.pl and args new *.pl

    as it runs from the command line ok I have to assume that this is a permissions issue perhaps?
    I hope you help as I want to get on and work my way through other exercises in my perl book.

    Heres my code, it looks for the word "new" in all perl programs in the current directory;

    #!/usr/bin/perl
    # perl-grep.pl
    my $regex = shift @ARGV;

    use Cwd;
    $dir = cwd();
    print "Current directory is ".$dir."\n";

    print "Regex is \n";
    while(<>)
            {
            print if m/$regex/;
            }

     
  • Jan Ploski
    Jan Ploski
    2010-03-06

    EPIC, unlike the shell, doesn't do any wildcard expansion on the command line arguments. So what your program receives as the argument is a literal "*.pl" string, which is obviously not a correct file name.

     
  • kac
    kac
    2010-03-06

    Thanks jploski, I appreciate that,
    I'll just work out how to list all the *.pl files in the directory and do it that way instead.

    Cheers
    K