[Chicago-talk] perl touch

warren at warrenandrachel.com warren at warrenandrachel.com
Tue May 9 18:48:52 PDT 2006


Touch never uses stdout, so capturing it won't do much good. Your best bet
is to simply do

  system 'touch', $foo or die "Failed to start touch!";
  die 'Call to touch failed!' if $?;

If you *really* must capture the error message, then this should work:

  $error = `system 'touch ' . quotemeta($foo) . ' 2>&1'`;
  die $error if $error;

But that gets rather confusing quite quickly.



>
>
> On Tue, 9 May 2006, tiger peng wrote:
>
>> > On 5/5/06 at 2:09 PM, tigerpeng2001 at yahoo.com (tiger
>> > peng) wrote:
>> > >
>> > > Can you help me to "touch" a file in perl without
>> > > using backticks? I do not feel comfotable with
>> > > backticks without catching its output.
>> >
>> > system("touch foo")
>>
>> not better than backticks, as there are even more
>> typing.
>
> Do you want to capture results?  Because you can with backticks:
>
> $return = `touch foo`;
>
> Maybe if we're all misunderstanding your intent, you could perhaps try to
> clarify what you're after?
>
> -Kent
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
>




More information about the Chicago-talk mailing list