Difference between revisions of "Perl tips"

From Chuckipedia
Jump to: navigation, search
Line 9: Line 9:
  
 
* https://perldoc.perl.org/functions/chop.html
 
* https://perldoc.perl.org/functions/chop.html
 +
 +
== Create path based on file name ==
 +
 +
<pre>
 +
use Path::Class;
 +
 +
my $destination_file  = file('tardir/dest1/dest2/test.txt');
 +
$destination_file->dir->mkpath;
 +
 +
# ... do the copying here
 +
</pre>
  
 
== References ==
 
== References ==
  
 
<references />
 
<references />

Revision as of 22:10, 30 November 2018

Undefine vars

You have several ways to undef a list of vars already. The most simple I know is
( $from, $to ) = (); 

[1]

Chop

Create path based on file name

use Path::Class;

my $destination_file  = file('tardir/dest1/dest2/test.txt');
$destination_file->dir->mkpath;

# ... do the copying here

References