Your snipped might work for your PC only and you'll
only see the last /dev/sr device - which might not be a CD or DVD at all.
The following suggestion is only a tiny improvement:
use strict;
# returns list of CD/DVD mountpoints or empty list
sub scan_cddvd {
my @drives = ();
my $mtabfile = "/etc/mtab";
open my $mtfh, "<", $mtabfile or die "cannot open $mtabfile - $!";
while( <$mtfh> ){
my ($dev, $mountpoint, $fstype, $options) = split /\s+/;
next unless $fstype =~ /udf|iso\d+/ && $options =~ /ro\b/;
#ro: the /ro/-test above should skip CDRW too
$mountpoint =~ s/\\(0\d+)/chr(oct($1))/eg; # resolve oct chars
push @drives, $mountpoint;
}
close $mtfh;
return @drives;
}
print "o <", join(">\no <", scan_cddvd), ">\n";
Things to note: uses strict; avoids "not found" as a special failure-indicator;
returns list of mountpoints; expands all octal escapes; less HW-dependent
(e.g. IDE, SCSI, SATA, ...), e.g. not restricted to /dev/sdb;
tries a little harder to find a CD or DVD (iso/udf,ro), uses 3 param
open and die; no globs (MYINPUTFILE); implicit use of $_; will fail for derviant mtab-formats;
...
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.