WaZaRWiki : PerlTips

GaelReignier :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register :: Hosted by: eNiX

Revision [337]

This is an old revision of PerlTips made by GaelReignier on 2009-10-04 14:15:20.
ITTips


How to use CPAN?


CPAN install module: to install a module

How to run a bash command in a Perl program: http://perl.about.com/od/programmingperl/qt/perlexecsystem.htm
system("myCommand"); i.e.: system("/bin/ls");

How to get the file size: http://www.perlmeme.org/faqs/file_io/filesize.html
$size = (-s 'ddserver.log');
print $size;

String comparison

if ($ticketList ne '')
##ne##: non equal
##eq##: equal


Pass array to sub-routines

Normally it is not possible to pass array to sub routines.
The only way to do so is to pass a reference to the array when calling the sub-routine and then to use it in the sub-routine

WriteChangesTofile($new_configuration_file,\@changed_file);

sub WriteChangesTofile{

        # Does not return anything. It OVERwrites the file
        my $new_configuration_file=$_[0];
        my @changed_file = @{$_[1]}; # This is the way to handle array passed to sub-routines. The array is passed as a reference

        print "Updating: ".$new_configuration_file."\n";
        open(NEW_CONF_FILE,">$new_configuration_file");
        print (NEW_CONF_FILE @changed_file);
        close(NEW_CONF_FILE);
}


Put some color in your life

Well, even if not in your life, at least in your script.
Reference website: http://docstore.mik.ua/orelly/perl/cookbook/ch15_06.htm
    use Term::ANSIColor;
    print color("red"), "Danger, Will Robinson!\n", color("reset");

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki
Page was generated in 0.3395 seconds