Professional Documents
Culture Documents
for internal use Copyright © Infineon Technologies AG 2014. All rights reserved. Page 2
Using Getopt::Long
Parses the command line from @ARGV, recognizing and removing
specified options and their possible values.
Basic Options:
The most simple options are the ones that take no values.
For options that take values: specify whether the option value is
required or not, and what kind of value the option expects.
¬ Required values: “=“
¬ Optional values: “:”
¬ Possible value types:
s : String value
i : Integer value
f : Float value
for internal use Copyright © Infineon Technologies AG 2014. All rights reserved. Page 3
Exercise 1: Using Getopt CPAN module
use Getopt::Long;
my $in_file = "";
my $out_file = "";
my $count = '';
my $help = '';
Exercises\Chapter_08_CPAN_Modules\Exercise1.pl
for internal use Copyright © Infineon Technologies AG 2014. All rights reserved. Page 4
Using File::Basename
fileparse : Used to parse file paths into their directory,
filename and suffix.
Suffix can be given as a list of strings, or as RegEx as well.
# Output
Path: /home/user/dir1/dir2/
Base: file3
Ext: .txt
for internal use Copyright © Infineon Technologies AG 2014. All rights reserved. Page 5
Using File::Basename [cntd…]
Note the output when the input path does not include filename.
It does NOT always return the file name portion of a path as you
might expect, just returns the “last level of a file path”.
To be safe, if you want the file name portion of a path use
fileparse().
for internal use Copyright © Infineon Technologies AG 2014. All rights reserved. Page 6
Using File::Basename [cntd…]
Note the output when the input path does not include filename.
In spite of its name, it does NOT always return the directory
name as you might expect.
To be safe, if you want the directory name portion of a path
use fileparse().
for internal use Copyright © Infineon Technologies AG 2014. All rights reserved. Page 7
Exercise 2: Using File::Basename module
for internal use Copyright © Infineon Technologies AG 2014. All rights reserved. Page 8
Exercise 3: Writing Excel file using
Spreadsheet::WriteExcel
# Add a worksheet
my $worksheet = $workbook->add_worksheet();
Exercises/Chapter_08_CPAN_Modules/Exercise4_read_excel.pl
for internal use Copyright © Infineon Technologies AG 2014. All rights reserved. Page 10