Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me with my Perl script? For some reason, open($info, >info.txt) clears the file but fails to write the data into it. I've

Can someone help me with my Perl script? For some reason, open($info, ">info.txt") clears the file but fails to write the data into it. I've used an array of methods for writing into the file, and even the append and "+" combinations fail to work. The "append" methods don't even write into the file at all. I've even used ">>", "+>", and "+>>" with no luck. The "w", "r", and "a" always gives me this: Can't open data at /cygdrive/c/Users/admin/Desktop/a14.pl line 11, line 3.

The current script I've attached to this message results in the following output: ------------------------------------------------------------------------------- admin@Dell /cygdrive/c/users/admin/desktop $ perl /cygdrive/c/Users/admin/Desktop/a14.pl

Full Name: Firstname Lastname

Age: 30

Gender: Female

Marital Status: Single

Do you want to change the age? (Y/y or N/n): y What is the new age? 27

Do you want to change the Marital Status? (Y/y or N/n): n The result is: Full Name: Age: Gender: Marital Status: admin@Dell /cygdrive/c/users/admin/desktop $ perl /cygdrive/c/Users/admin/Desktop/a14.pl

Full Name: Age: Gender: Marital Status:

Do you want to change the age? (Y/y or N/n):

admin@Dell /cygdrive/c/users/admin/desktop $

-------------------------------------------------------------------------------

Here's the script -------------------------------------------------------------------------------

#!/usr/bin/perl open(DATA,"; $file[1]=; $file[2]=; $file[3]=; close (DATA); print " Full Name: $file[0] Age: $file[1] Gender: $file[2] Marital Status: $file[3]"; print " Do you want to change the age? (Y/y or N/n): "; $a = ; chomp($a); if($a eq'Y' or $a eq 'y'){ print "What is the new age? "; $file2[1]= ; $c=$a; } print " Do you want to change the Marital Status? (Y/y or N/n): "; $b = ; chomp($b); if($b eq 'Y' or $b eq 'y') { print "What is the new marital status? "; $file2[3] = ; $c=$b; } if($c eq 'Y' or $c eq 'y') { $file2[0]=$file[0]; $file2[2]=$file[2]; open($info, "> info.txt") or die "Can't open data"; $info = join('',$file2[0], $file2[1], $file2[2], $file2[3]); close $info;

open(DATA,"; $file[1]=; $file[2]=; $file[3]=; close (DATA); print "The result is: Full Name: $file[0] Age: $file[1] Gender: $file[2] Marital Status: $file[3]"; }

Is it because Cygwin's incompatible? Is it the script itself? I don't know if it's a software issue, an error in my script, or if it's my system. Is there any advice or tips that you can provide? Thank you.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions