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!

Need to replace __DATA__ with variable

Status
Not open for further replies.

itmiami

IS-IT--Management
Joined
Mar 10, 2007
Messages
3
Location
US
Hello I have a code that uses the __DATA__ perl function to save the date below the code, I need to switch that to use data from a variable, but it goes into infinite loop does anyone knows to can I get around this?

# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
here is the code:
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
while( <DATA> ){
(@date,@start,@end,$employee);
(@date[0..2],@start[0,1],@end[0,1],$employee)=(split/\|/)[0..2,3..4,6..7,10];
push @{$schedule{$employee}},["@date",$start[0]*60+$start[1],$end[0]*60+$end[1]];
}
__DATA__
2007|3|21|12|00||14|00||FT|employee4
2007|3|21|12|00||14|00||KT|employee8
2007|3|21|14|00||16|00||DV|employee3
2007|3|21|14|00||16|00||AC|employee1
2007|3|21|16|00||18|00||VS|employee4

# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
I tried:
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$var_records = qq~
2007|3|21|12|00||14|00||FT|employee4
2007|3|21|12|00||14|00||KT|employee8
2007|3|21|14|00||16|00||DV|employee3
2007|3|21|14|00||16|00||AC|employee1
2007|3|21|16|00||18|00||VS|employee4
~
while($var_records){
(@date,@start,@end,$employee);
(@date[0..2],@start[0,1],@end[0,1],$employee)=(split/\|/)[0..2,3..4,6..7,10];
push @{$schedule{$employee}},["@date",$start[0]*60+$start[1],$end[0]*60+$end[1]];
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Thanks
 
There is a missing ";" for $var_records and instead of while use foreach loop.
 
Thanks,

I forgot to copy the ;, but if I do a foreach loop it does not work, I'm new to perl this code was writen by someone else

 
some odd code, but....

Code:
$var_records = q~
2007|3|21|12|00||14|00||FT|employee4
2007|3|21|12|00||14|00||KT|employee8
2007|3|21|14|00||16|00||DV|employee3
2007|3|21|14|00||16|00||AC|employee1
2007|3|21|16|00||18|00||VS|employee4
~;

for(split("\n",$var_records)){
    (@date,@start,@end,$employee);
    (@date[0..2],@start[0,1],@end[0,1],$employee)=(split/\|/)[0..2,3..4,6..7,10];
    push @{$schedule{$employee}},["@date",$start[0]*60+$start[1],$end[0]*60+$end[1]];
}

are you reading the data in from a file? If so, just process the file the same as you would with __DATA__. I don't understand why you are using all these variables:

(@date,@start,@end,$employee);



------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
I'm getting this info from an existing script and need to validate some info before saving it...

It worked, thanks a lot...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top