Solved

Writing a file online a WEB Browers

Posted on 2000-02-23
8
156 Views
Last Modified: 2010-03-05
This is a part of a script Perl to write a file to the Server. This write it in DOS Format.
My question is what to do with this script to write it in UNIX Format ?


sub write {
    my ($directory, $filename, $data, $url) = @_;
    my ($fullfile, $new);

    (!$filename) and return "Edit File: No filename was entered!";

    ($directory =~ m,/$,) ? ($fullfile = "$directory$filename") : ($fullfile = "$directory/$filename");

existing file.
    $new = 1;
    (&exists($fullfile)) and ($new = 0);

    $data =~ s,</TEXT-AREA,</TEXTAREA,ig;

# Write the file to the system.
    open(FILE,">$fullfile") or &cgierr ("Can't open: '$fullfile'.\nReason: $!");
        print FILE $data;
    close(FILE);

    if (&exists($fullfile)) {
        ($new eq 'yes') ?
            return ("Edit File: '$filename' has been created.") :
            return ("Edit File: '$filename' has been edited.");
    }
    else {
        return  ("Edit File: Cannot save '$filename'. Check permissions.");
    }
}

Thank you for helping.

jvras
0
Comment
Question by:jvras
8 Comments
 
LVL 8

Expert Comment

by:shlomoy
Comment Utility
looks like it's going to work.
0
 

Author Comment

by:jvras
Comment Utility
No, it's not working.

I change a perl script online and after rewrite it it's give an error.
The reason is that it's writed in DOS Format.
I have to remove the ^M and ^Z characters.
What is the code for that in this script? And where I have to place it.

Thanks
jvras
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
try adding this ....


open(FILE,">$fullfile") or &cgierr ("Can't open: '$fullfile'.\nReason: $!");

binmode(FILE); ## Add this line to your program


Let me know if it works
0
 
LVL 3

Accepted Solution

by:
monas earned 200 total points
Comment Utility
put
$data =~ s/(\r|\035)//gi;

right after $data =~ s,</TEXT....

I'm little unsure about \035 but this should be code of ^Z in octal.

Good Look!
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:jvras
Comment Utility
This is working correctly.
The code is for ^M but not for ^Z

Many thanks to monas

0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
to make it work for ^Z try this


$data=~ s/^Z//g;

NOTE: the above is not 2 chars (^ and Z) but a single char.
you can reproduce that single char in the following way, assuming you are on a UNIX based system and use vi editor.

To get ^Z char:
In vi
* press escape
* press i
* press CTRL + V and keeping the CTRL key depressed press Z.
that will give you the ^Z  char. You can use the same method to reproduce ^M.
* press escape again

if you want i can send you the script, via email, as an attachment since i cannot directly paste the code here.
0
 

Author Comment

by:jvras
Comment Utility
maneshr

Thanks for reply but I know the vi editor how to make special characters.

Your first responce about binmode isn't working. That is what I also thinking before but the answer of  monas  is
the best one.

Still thank you.
jvras
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
you're welcome :-)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now