Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl file input multiple lines to an array

Status
Not open for further replies.

uscetech

Programmer
Joined
Oct 25, 2006
Messages
7
Location
US
Hey all,

Just wanted to ask a question that's been burning in my head for some time now. Here's an example of a script that I want to modify.

$itemType = "PC";

sub get_item_weight
{
$itemWeight = "";

if ( $itemType eq "PC" ) {
$itemWeight = "50";
}
elsif ( $itemType eq "CPU" ) {
$itemWeight = "10";
}
}

I'm trying to make a script that will edit another script :P Basically I need a front-end that anybody at my work can use, none of them have even heard of perl. I'm trying to make it so they can add to the script from a html form gui. But the problem I'm having is opening the script and imputing certain sections to arrays or strings.

What I need it to do is something allong the lines of opening the file and push everything between "sub get_item_weight {" and the closing sub char "}".

So that array will contain:
$itemWeight = "";

if ( $itemType eq "PC" ) {
$itemWeight = "50";
}
elsif ( $itemType eq "CPU" ) {
$itemWeight = "10";
}

Than I need to go one step further and be able to push everything from "if ... }" or "elsif ... }" to an array or string.

The problem is that I really only know how to input one line at a time. And I want it to grab anything between { and }. Anyone know how to do that? I would greatly appricate it.

Thanks
 
The only reason the weights are in cgi form is that there are item types that have many different weights. The type "PRNT" (Printers) is a good example, this type has 20lb deskjets to 200lb plotters. Someone else handles what items go in what item type, that's out of my hands. Although, I have been trying. If I could get them to fix their inventory, or at leaste sort it in some kind of orderly fashion, I would be much better off.

So the only thing I can think of is something like:

if ( $itemType eq "PRNT" ) { #Desktop PC
if ( $itemDescription =~ /printer/i ) {
$itemWeight = "20";
}
elsif ( $itemDescription =~ /plotter/i ) {
$itemWeight = "200";
}
else {
$itemWeight = "UNKNOWN";
}
}

Then I open the resulting output file and look for "UNKNOWN" and add snother elsif to assign that item to a weight. The report has roughly 10,000 items.
 
I guess I am still not understanding something.

- Kevin, perl coder unexceptional!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top