Advertisement

02.27.2008 at 08:21AM PST, ID: 23197372
[x]
Attachment Details

Perl conditional statement not working

Asked by isaacr25 in Perl Programming Language, Scripting Languages

Please see the attached code snippet. Using an example form a previous solution, I'm trying to use the following if statements in the script:

substr($_, 7, 1, "B") if substr($_, 7, 1) eq "0";
substr($_, 0, 4, "0001") if substr($_, 0, 4) eq "4990";
substr($_, 0, 4, "0002") if substr($_, 0, 4) eq "8990";

The first one works fine, but the second two are not working.

If the first 4 characters of the output file are '0001' the they needs to be changed to '4990'

If the first 4 characters of the output file are '0002' then they need to be changed to '8990'

Please help!Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
while( <> ){
my $str = " " x 68;     #make a string xx spaces
 
substr($_, 7, 1, "B") if substr($_, 7, 1) eq "0";
substr($_, 0, 4, "0001") if substr($_, 0, 4) eq "4990";
substr($_, 0, 4, "0002") if substr($_, 0, 4) eq "8990";
substr($str, 0, 4, substr($_, 12, 4));       #pull from positions 13-16, insert to 1-4
substr($str, 22, 4, substr($_, 4, 4));
substr($str, 4, 16, substr($_, 60, 16));   #pull from positions 61-80 (offset 60, length 20), insert to 5-20
substr($str, 26, 2, substr($_, 83, 2));
substr($str, 32, 8, substr($_, 119, 8));
substr($str, 50, 8, substr($_, 132, 8));
substr($str, 59, 8, substr($_, 132, 8));
 
 
substr($str, 20, 1, "T");
substr($str, 21, 1, "D");
substr($str, 28, 1, "A");
substr($str, 58, 1, " ");
substr($str, 67, 1, " ");
print "$str\n";
}
[+][-]02.27.2008 at 08:24AM PST, ID: 20995316

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]02.27.2008 at 08:27AM PST, ID: 20995352

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.27.2008 at 08:43AM PST, ID: 20995513

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]02.27.2008 at 08:46AM PST, ID: 20995546

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.27.2008 at 08:47AM PST, ID: 20995559

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.27.2008 at 08:49AM PST, ID: 20995575

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.27.2008 at 09:13AM PST, ID: 20995875

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.27.2008 at 09:48AM PST, ID: 20996364

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.27.2008 at 10:06AM PST, ID: 20996578

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]02.27.2008 at 11:13AM PST, ID: 20997277

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.27.2008 at 11:22AM PST, ID: 20997348

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.27.2008 at 11:24AM PST, ID: 20997369

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.27.2008 at 11:37AM PST, ID: 20997521

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Perl Programming Language, Scripting Languages
Sign Up Now!
Solution Provided By: Adam314
Participating Experts: 4
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628