Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8552285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:23:31+00:00 2026-06-11T14:23:31+00:00

I got this perl example that’s suppose to demonstrate sysopen and printf , except

  • 0

I got this perl example that’s suppose to demonstrate sysopen and printf, except so far it only demonstrates die.

#! /usr/bin/perl  
$filepath = 'myhtml.html';
sysopen (HTML, $filepath, O_RDWR|O_EXCL|O_CREAT, 0755) 
    or die "$filepath cannot be opened.";
printf HTML "<html>\n";

but when I execute the code it just dies.

myhtml.html cannot be opened. at file_handle.pl line 7.

myhtml.html does not exist, but it should have been created by the O_CREAT flag. shouldn’t it?


EDIT

I have edited the code to include the suggestions about use strict and $!. Below is the new code and its result.

#! /usr/bin/perl
use strict; 
$filepath = "myhtml.html";

sysopen (HTML, '$filepath', O_RDWR|O_EXCL|O_CREAT, 0755) 
    or die "$filepath cannot be opened. $!";
printf HTML "<html>\n"; 

output, due to the use strict, gave us a whole bunch of errors:

Global symbol "$filepath" requires explicit package name at file_handle.pl line 3.
Global symbol "$filepath" requires explicit package name at file_handle.pl line 5.
Bareword "O_RDWR" not allowed while "strict subs" in use at file_handle.pl line 5.
Bareword "O_EXCL" not allowed while "strict subs" in use at file_handle.pl line 5.
Bareword "O_CREAT" not allowed while "strict subs" in use at file_handle.pl line 5.
Execution of file_handle.pl aborted due to compilation errors.

EDIT 2

Based on everyone’s suggestion and help, here is the final working code:

#! /usr/bin/perl
use strict;
use Fcntl;

my $filepath = "myhtml.html";

sysopen (HTML, $filepath, O_RDWR|O_EXCL|O_CREAT, 0755) 
    or die "$filepath cannot be opened. $!";
printf HTML "<html>\n"; 
....
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:23:32+00:00Added an answer on June 11, 2026 at 2:23 pm

    O_RWDR, O_EXCL, and O_CREAT are all constants defined in the Fcntl module.
    Put the line

    use Fcntl;
    

    near the top of your script.

    You can limit the imported variables as follows.

    # import only needed constants.  
    use Fcntl qw(O_CREAT O_WRONLY O_TRUNC);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a one-liner like this: date +%H | perl -ne 'printf %02d, $_
I've got this simple Perl script: #! /usr/bin/perl -w use strict; use Data::Dumper; my
So I finally got my boss to approve the use of perl for this
Replacing the Special Character using Perl while i am doing this . I got
I tried to solve this problem in PERL, but it only works with lesser
I downloaded HTTP::Daemon::SSL for Strawberry Perl 5.10 from CPAN and ran this example: use
I have this Perl subroutine that is causing a problem: sub new { my
I ran Perl::Critic on one of my scripts, and got this message: Regular expression
I've got an array in perl which contains sorted non-contiguous values. For example: 1
Thinking that to solve a problem I've got this is the fastest solution: Generate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.