Still need unlink help!! God help me. - Revisited

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default Re: Still need unlink help!! God help me. - Revisited







    <20030808202717051099.GyazMail.neuroball@usa.net >







    <YW50aWdvbmU=.45ab06a65368617cf57750f9f6311818@106 0402929.cotse.net>







    <20030808223332494596.GyazMail.neuroball@usa.net >
    <YW50aWdvbmU=.b5f5cdebb1363e9b5422d22aeff7ce2e@106 0449982.cotse.net>
    <BAY1-DAV43JqxyBidAz000261ff@hotmail.com>
    X-Priority: 3
    Importance: Normal
    X-MSMail-Priority: Normal
    Cc: <dunc339cowley@hotmail.com>
    Reply-To: [email]perlwannabe@antigone.cotse.net[/email]
    X-Mailer: [url]www.cotse.net[/url]
    MIME-Version: 1.0
    Content-Type: text/plain; charset=iso-8859-1
    Content-Transfer-Encoding: 8bit
    Approved: [email]news@nntp.perl.org[/email]
    From: [email]perlwannabe@antigone.cotse.net[/email] (Perlwannabe)
    Lines: 20
    Xref: intern1.nntp.aus1.giganews.com perl.beginners:123
    > This works - i've tried it...
    >
    > print 'Deleted ' , unlink (<*997*>) , ' files.\n';
    >
    > good luck
    > Duncan
    Yes, it does. But it does not work when reading from a variable.

    my $temp = '*997*';
    print 'Deleted ' , unlink (<$temp>) , ' files.\n';

    This very simple variation of your example does not work.

    The problem is that I have to read from a file and put the value from the
    file into a variable. Although your "hard coded" example does work, it
    doesn't work for a value read in from an external file and into a
    variable. Any other ideas? I am all ears and out of ideas.


    Guest

  2. Similar Questions and Discussions

    1. Unlink and variables
      Hello, I created a form to upload files. The formfield contents are stored as records in an Ascii file "data.dat"; for reasons I am not using a...
    2. Still need unlink help!! God help me.
      Still having problem with unlink. My original problem began with deleting files from a list. I seem to have fixed the problem reading the list but...
    3. Help with Unlink please
      > Steve Grazzini wrote at Wed, 06 Aug 2003 23:38:00 -0400: Neither of these worked. I am beginning to think that there is something wrong with...
    4. problem using unlink()
      Hi, I have a problem using unlink(); on a system using FreeBSD and Apache... where my local system using Windows and Apache experiences no...
    5. unlink() in a loop???
      I have a script that allows users to upload pics and enter personal info into Database (not pictures i only store filename in db). The form passes...
  3. #2

    Default Re: Still need unlink help!! God help me. - Revisited

    "Perlwannabe" <perlwannabe@antigone.cotse.net> wrote in message
    news:YW50aWdvbmU=.bca259c206ff92e930679e970dbc8699 @1060478346.cotse.net...
    > > This works - i've tried it...
    > >
    > > print 'Deleted ' , unlink (<*997*>) , ' files.\n';
    > >
    > > good luck
    > > Duncan
    >
    > Yes, it does. But it does not work when reading from a variable.
    >
    > my $temp = '*997*';
    > print 'Deleted ' , unlink (<$temp>) , ' files.\n';
    >
    > This very simple variation of your example does not work.
    the reason why YOUR version won't work is because when Perl sees '<$temp>',
    it's trying to read from the file handle '*997*'. it's NOT doing glob for
    you. example:

    my $s = '*.pl';
    my @c = ('*.pl');

    #--
    #-- even though the following 2 lines seems identical and should work to
    give you
    #-- all file names ending with *.pl in the current directory, only the
    second version really works
    #--
    my @files1 = <$s>; #-- this does not work because Perl is trying to read
    from the '*.pl' file handle!
    my @files2 = <$c[0]>; #-- this does work. see reason below

    for(@files1){
    print "\@files1: $_\n";
    }

    for(@files2){
    print "\@files2: $_\n"; #-- only this get print out.
    }

    to make the long story short: Perl consider $s to be a simple scalar (and
    yes that's the official term) and whenever a simple scalar is put inside
    '<>', Perl assumes it's a file handle that you are trying to read from.
    otherwise, you can't even:

    open(my $file,'some.txt') || die;
    while(<$file>){ #-- doing glob or reading from $file?
    #-- code
    }
    close($file);

    it's reading from $file (the file handle) because $file is a considered to
    be a simple scalar. now if you were to change your script to look like:

    my $temp = '*997*';
    print 'Deleted ' , unlink (<@{[$temp]}>) , ' files.\n';

    it will work because that tells Perl the stuff inside '<>' is not a file
    handle so it should be handed to the glob function.
    >
    > The problem is that I have to read from a file and put the value from the
    > file into a variable. Although your "hard coded" example does work, it
    > doesn't work for a value read in from an external file and into a
    > variable. Any other ideas? I am all ears and out of ideas.
    >
    if you were really "all ears out", you should have tell us where all of your
    files live and how (and where) you execute your script. i still think your
    problem is largely related to Perl not able to find the files because you
    are running the script from a different directory.

    david


    David Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139