Difference between revisions of "Perl tips"

From Chuckipedia
Jump to: navigation, search
(Created page with "== Undefine vars == <pre> You have several ways to undef a list of vars already. The most simple I know is ( $from, $to ) = (); </pre> <ref> https://www.perlmonks.org/?node...")
 
 
(2 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
( $from, $to ) = ();  
 
( $from, $to ) = ();  
 
</pre> <ref> https://www.perlmonks.org/?node_id=426526 </ref>
 
</pre> <ref> https://www.perlmonks.org/?node_id=426526 </ref>
 +
 +
== Chop ==
 +
 +
* 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 />
 +
 +
[[Category:Tips]]

Latest revision as of 22:33, 14 January 2023

Undefine vars[edit]

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

[1]

Chop[edit]

Create path based on file name[edit]

use Path::Class;

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

# ... do the copying here

References[edit]