I'm assuming then that each line is the name of a folder, spaces included. A bit of RegEx would do, as in the code below.
I'm sure the RegEx section could be redone to be cleaner and smaller, but I'm not at that level yet :) so I just did it in seperate steps.
use strict;
my $Car0 = "2011 Chevy Camaro";
my $Car1 = "2011 Dodge Ram Crew Cab Short Bed";
my $Car2 = "2011 Ford F150 Platinum";
my $Car3 = "2011 Ford Flex";
my $Car4 = "2011 Ford Transit";
my $Car5 = "2011 GMC Cargo Van Extended";
my $Car6 = "2011 Hyundai Genesis Coupe";
my $Car7 = "2011 Kia Sol";
my $Car8 = "2011 Nissan Cube";
my $Car9 = "2011 Toyota Prius";
my $OneCar = "";
my $Year = 0;
my $Make = "";
my $Model = "";
push( my @CarInfo, ( $Car0, $Car1, $Car2, $Car3, $Car4, $Car5, $Car6,
+$Car7, $Car8, $Car9 ) );
foreach $OneCar( @CarInfo )
{
# initialize the variables
$Year = $OneCar; $Make = $OneCar; $Model = $OneCar;
# drop everything after the Year including the first space char
$Year =~ s/\s.*//;
# drop the year and the first space char
$Make =~ s/\d*\s*//;
# drop everything after the Make including the first space char
$Make =~ s/\s.*//;
# drop the year and the first space char, same as with $Make
$Model =~ s/\d*\s//;
# drop everything up to and including the first space char
$Model =~ s/\w*\s//;
print "$Year\t\t$Make\t\t$Model\n";
}
-
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.