Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19
Some Perl Questions, File::Find Module
Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: Some Perl Questions, File::Find Module

  1. #1

    Some Perl Questions, File::Find Module

    Hi! I am working for my school's Athletic Department and I was just wondering how can I assign a file to a scalar variable.

    Here is what I mean:

    $sourcedir = "/var/www/cgi-bin/source.pl";

    is that possible? so when ever I refer to $sourcedir, I am actually referring to source.pl located in the directory above...

    thanks!

  2. #2

    Re:Some Perl Questions

    Are you talking about file path or the contents of the file?

  3. #3

    Re:Some Perl Questions

    [quote author=chessforce link=board=9;threadid=8862;start=0#msg80022 date=1079527207]
    Are you talking about file path or the contents of the file?
    [/quote]


    I need to access the contents of the file.

  4. #4
    Senior Member
    Join Date
    Apr 2002
    Posts
    417

    Re:Some Perl Questions

    It depends on how you want to access the contents. You actually use something called a file handle to read/write to the contents of a file.

    You read the contents of a file like this.

    my $filename="/tmp/filename.pl";

    open(FILEHANDLENAME, $filename) || die "Could not open file,$!\n";
    my @array = <FILENHANDLENAME>;
    close(FILEHANDLENAME);

    print @array;


    If wanted to print something out to a file then you would do this.

    open(FILEHANDLENAME, ">$filename") || die "Could not open file,$!\n";

    print FILEHANDLENAME "This line will be printed out to $filename\n";
    close(FILEHANDLENAME);

    The code above will create/write-over the file $filename. If you wanted to append (write to the end of) a file then you would use '>>' instead of '>'

    If you are really new to perl then, I would suggest getting a nice used book on ebay.

    HTH

  5. #5
    Mentor Stuart's Avatar
    Join Date
    May 2002
    Location
    nb.ca
    Posts
    1,087

    Re:Some Perl Questions

    Just to add my two cents, a good beginners book is Sam's Teach Yourself Perl In 24 Hours.

  6. #6

    Re:Some Perl Questions

    Thanks! I have all the books from OReilly and * for dummies books for Perl. But I couldn't find it there but anyways thanks!

  7. #7

    Re:Some Perl Questions, File::Find Module

    Hi! I have some File::Find Questions, I just want to know if I am using it right because it gives me some errors:


    Code:
    #!/usr/bin/perl -w
    
    use strict;
    use warnings;
    use File::Find;
    
    my @directories = ('/var/tmp/', '/home/shebang/' , '/var/www/')
    
    finddepth('perl' , @directories);
    Shouldn't it return the things that it finds should have 'perl' in the name?

  8. #8

    Re:Some Perl Questions, File::Find Module

    um, could you please post the errors too?

  9. #9

    Re:Some Perl Questions, File::Find Module

    [quote author=countach44 link=board=9;threadid=8862;start=0#msg80157 date=1079733446]
    um, could you please post the errors too?
    [/quote]

    Code:
    Can't use string ("perl") as a subroutine ref while "strict refs" in use at /usr/lib/perl5/5.8.2/File/Find.pm line
    So does it want the "perl" to be a subroutine? If so, what can I put in the subroutine?

  10. #10

    Re:Some Perl Questions, File::Find Module

    Here's what I got from CPAN
    Code:
        use File::Find;
        finddepth(\&wanted, @directories_to_search);
        sub wanted { ... }
    so yes, "perl" must be a subroutine
    also,
    Code:
    The wanted() function does whatever verifications you want on each file and directory. It takes no arguments but rather does its work through a collection of variables.
    
    $File::Find::dir is the current directory name,
    $_ is the current filename within that directory
    $File::Find::name is the complete pathname to the file.
    
    Don't modify these variables.
    
    For example, when examining the file /some/path/foo.ext you will have:
    
        $File::Find::dir  = /some/path/
        $_                = foo.ext
        $File::Find::name = /some/path/foo.ext

Similar Threads

  1. Perl module problem
    By Outlaw in forum Linux - Software, Applications & Programming
    Replies: 3
    Last Post: 05-04-2005, 02:17 PM
  2. newbie perl question using Net::OSCAR module
    By countach44 in forum Linux - Software, Applications & Programming
    Replies: 12
    Last Post: 12-10-2003, 04:09 AM
  3. MP3::Info (perl module)
    By in forum Linux - Software, Applications & Programming
    Replies: 2
    Last Post: 07-20-2002, 10:10 PM
  4. perl, including a file /more/ than once
    By gorn in forum Linux - Software, Applications & Programming
    Replies: 4
    Last Post: 07-08-2002, 10:18 PM
  5. COmmands. Trying to find a file on server
    By mudflap in forum Linux - Hardware, Networking & Security
    Replies: 2
    Last Post: 02-25-2002, 10:46 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •